@degreesign/chat 1.1.0 → 1.3.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 +145 -126
- package/dist/browser/chat.min.mjs +1 -1
- package/dist/browser/engine-wllama.min.mjs +1 -1
- package/dist/chat.d.ts +4 -4
- package/dist/describe.d.ts +16 -7
- package/dist/engines/engine.d.ts +12 -12
- package/dist/engines/images.d.ts +8 -8
- package/dist/engines/litert.d.ts +22 -10
- package/dist/engines/store.d.ts +4 -4
- package/dist/engines/threads.d.ts +1 -1
- package/dist/engines/wllama.d.ts +4 -4
- package/dist/enums.d.ts +6 -7
- package/dist/index.d.ts +2 -1
- package/dist/log.d.ts +1 -1
- package/dist/models.d.ts +12 -12
- package/dist/node/chat.node.min.js +1 -1
- package/dist/node/chat.node.min.mjs +1 -1
- package/dist/node/engine-wllama.node.min.js +1 -1
- package/dist/node/engine-wllama.node.min.mjs +1 -1
- package/dist/tools/calculator.d.ts +2 -2
- package/dist/tools/currency.d.ts +3 -3
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/search.d.ts +3 -3
- package/dist/tools/text.d.ts +3 -3
- package/dist/types.d.ts +216 -173
- package/package.json +4 -2
package/dist/chat.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ChatModelId } from './enums';
|
|
2
2
|
import type { CancelChat, ChatInput, ChatPreloadInput, ChatState, ChatStatusSnapshot, Runtime } from './types';
|
|
3
|
-
/** Build one
|
|
3
|
+
/** Build one status snapshot */
|
|
4
4
|
declare const statusSnapshot: (service: Runtime, model: ChatModelId | undefined, state: ChatState) => ChatStatusSnapshot;
|
|
5
|
-
/** Build
|
|
5
|
+
/** Build chat over one runtime */
|
|
6
6
|
declare const createChatOn: (service: Runtime) => ((input: ChatInput) => CancelChat);
|
|
7
|
-
/** Build
|
|
7
|
+
/** Build preload over one runtime */
|
|
8
8
|
declare const createPreloadOn: (service: Runtime) => (input?: ChatPreloadInput) => Promise<boolean>;
|
|
9
9
|
declare const createChat: (input: ChatInput) => CancelChat;
|
|
10
10
|
declare const preloadModel: (input?: ChatPreloadInput) => Promise<boolean>;
|
|
11
|
-
/** Delete every model file
|
|
11
|
+
/** Delete every cached model file */
|
|
12
12
|
declare const clearModelCache: () => Promise<void>;
|
|
13
13
|
export { clearModelCache, createChat, createChatOn, createPreloadOn, preloadModel, statusSnapshot, };
|
package/dist/describe.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { ChatModelId } from './enums';
|
|
2
2
|
import type { DescribeImagesInput, DescribeTranslatedInput, ImageDescription, Runtime } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
declare const
|
|
4
|
+
/** System message of the describer */
|
|
5
|
+
imageSystem: string,
|
|
6
|
+
/** System image rules */
|
|
7
|
+
imageRules: string,
|
|
8
|
+
/** Request for every image */
|
|
9
|
+
imageNote = "Describe all elements of the image.";
|
|
10
|
+
/** Reply budget, about 100 words */
|
|
11
|
+
declare const imageReplyTokens = 128;
|
|
12
|
+
/** Describer model, Q4 CPU build */
|
|
13
|
+
declare const describeModelId = ChatModelId.qwen3_vl_2b_instruct;
|
|
14
|
+
/** Build descriptions over one runtime */
|
|
6
15
|
declare const createDescribeOn: (service: Runtime) => (input: DescribeImagesInput) => Promise<ImageDescription[]>;
|
|
7
|
-
/** Build translations
|
|
16
|
+
/** Build translations over one runtime */
|
|
8
17
|
declare const createTranslateOn: (service: Runtime) => (input: DescribeTranslatedInput) => Promise<string[]>;
|
|
9
|
-
/** Describe
|
|
18
|
+
/** Describe images in English, translate */
|
|
10
19
|
declare const describeImages: (input: DescribeImagesInput) => Promise<ImageDescription[]>;
|
|
11
|
-
/** Translate
|
|
20
|
+
/** Translate image descriptions on GPU */
|
|
12
21
|
declare const describeTranslated: (input: DescribeTranslatedInput) => Promise<string[]>;
|
|
13
|
-
export { createDescribeOn, createTranslateOn, describeImages, describeModelId, describeTranslated, };
|
|
22
|
+
export { createDescribeOn, createTranslateOn, describeImages, describeModelId, describeTranslated, imageNote, imageReplyTokens, imageRules, imageSystem, };
|
package/dist/engines/engine.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import type { ChatMessage, ChatModel, EngineMessage, EngineRunParams, LlmLimits, StreamReplyParams } from '../types';
|
|
2
|
-
/** Default
|
|
2
|
+
/** Default CPU engine budgets */
|
|
3
3
|
declare const defaultLlmLimits: LlmLimits;
|
|
4
|
-
/** Merge
|
|
4
|
+
/** Merge budgets over backend defaults */
|
|
5
5
|
declare const resolveLlmLimits: (overrides?: Partial<LlmLimits>, gpu?: boolean) => LlmLimits;
|
|
6
|
-
/** Sampling options
|
|
7
|
-
declare const replyOptions: (limits: LlmLimits, reasoning: boolean) => {
|
|
6
|
+
/** Sampling options for every stream */
|
|
7
|
+
declare const replyOptions: (limits: LlmLimits, reasoning: boolean, temperature?: number) => {
|
|
8
8
|
stream: true;
|
|
9
9
|
temperature: number;
|
|
10
10
|
max_tokens: number;
|
|
11
11
|
};
|
|
12
12
|
declare const
|
|
13
|
-
/** Resolve one model file
|
|
13
|
+
/** Resolve one model file URL */
|
|
14
14
|
modelUrl: (repo: string, file: string) => string,
|
|
15
|
-
/** Declared size
|
|
15
|
+
/** Declared download size or zero */
|
|
16
16
|
contentLength: (response: Response) => number,
|
|
17
|
-
/**
|
|
17
|
+
/** Any turn carries an image */
|
|
18
18
|
hasImages: (messages: EngineMessage[]) => boolean,
|
|
19
19
|
/** Whether any turn carries audio */
|
|
20
20
|
hasAudio: (messages: EngineMessage[]) => boolean;
|
|
21
21
|
declare const
|
|
22
|
-
/** Map
|
|
22
|
+
/** Map host messages to turns */
|
|
23
23
|
buildMessages: (messages: ChatMessage[], limits?: LlmLimits) => EngineMessage[],
|
|
24
|
-
/** Split
|
|
24
|
+
/** Split reasoning markers from content */
|
|
25
25
|
createThinkSplitter: (onReason: (text: string) => void, onText: (text: string) => void) => {
|
|
26
26
|
feed: (text: string) => void;
|
|
27
27
|
flush: () => void;
|
|
28
28
|
};
|
|
29
29
|
declare const
|
|
30
|
-
/** Log
|
|
30
|
+
/** Log chat call, text censored */
|
|
31
31
|
logChatCall: (model: ChatModel, messages: EngineMessage[]) => void,
|
|
32
|
-
/** Stream
|
|
32
|
+
/** Stream reply, undefined when stopped */
|
|
33
33
|
streamReply: ({ model, logging, onReason, onText, onSpeed, start, stopped, firstTimeoutMs, idleTimeoutMs, onStall, }: StreamReplyParams) => Promise<string | undefined>;
|
|
34
34
|
declare const
|
|
35
|
-
/** Build
|
|
35
|
+
/** Build prompt, stream through engine */
|
|
36
36
|
runEngineChat: ({ model, params, start, stopped, onStall, }: EngineRunParams) => Promise<string | undefined>;
|
|
37
37
|
export { buildMessages, createThinkSplitter, logChatCall, runEngineChat, streamReply, replyOptions, defaultLlmLimits, resolveLlmLimits, hasImages, hasAudio, modelUrl, contentLength, };
|
package/dist/engines/images.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ imageTokens = 128,
|
|
|
6
6
|
tokenCell = 32,
|
|
7
7
|
/** Tokens allowed above the target */
|
|
8
8
|
tokenSlack = 8;
|
|
9
|
-
/** Square size
|
|
9
|
+
/** Square size for WebGPU encoding */
|
|
10
10
|
declare const gpuImageSize: ImageSize;
|
|
11
|
-
/** Decode
|
|
11
|
+
/** Decode URL into engine bytes */
|
|
12
12
|
declare const contentBuffer: (url: string) => Promise<ArrayBuffer>;
|
|
13
|
-
/** Full-frame size near
|
|
14
|
-
declare const visionSize: (width: number, height: number) => ImageSize;
|
|
15
|
-
/** Fit
|
|
16
|
-
declare const resizeImageUrl: (url: string, size?: ImageSize) => Promise<string>;
|
|
17
|
-
/** Fit
|
|
18
|
-
declare const resizeImages: (messages: EngineMessage[], size?: ImageSize) => Promise<EngineMessage[]>;
|
|
13
|
+
/** Full-frame size near token target */
|
|
14
|
+
declare const visionSize: (width: number, height: number, tokens?: number) => ImageSize;
|
|
15
|
+
/** Fit image to token grid */
|
|
16
|
+
declare const resizeImageUrl: (url: string, size?: ImageSize, tokens?: number) => Promise<string>;
|
|
17
|
+
/** Fit image parts before engine */
|
|
18
|
+
declare const resizeImages: (messages: EngineMessage[], size?: ImageSize, tokens?: number) => Promise<EngineMessage[]>;
|
|
19
19
|
export { gpuImageSize, imageTokens, tokenCell, tokenSlack, visionSize, contentBuffer, resizeImageUrl, resizeImages, };
|
package/dist/engines/litert.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { loadLitert } from './litertLoader';
|
|
2
|
+
import type { EngineChunk, EngineMessage, GpuDevice, GpuThrottleParams, LitertMessage, LitertSettings, LitertSettingsParams, LlmEngine, StartLlmParams, StreamLitertParams } from '../types';
|
|
2
3
|
declare const
|
|
3
|
-
/** Smallest Gemma 4 vision budget
|
|
4
|
-
visionTokens = 70
|
|
5
|
-
/**
|
|
4
|
+
/** Smallest Gemma 4 vision budget */
|
|
5
|
+
visionTokens = 70,
|
|
6
|
+
/** GPU busy share of time */
|
|
7
|
+
gpuShare = 0.7,
|
|
8
|
+
/** Most rest per readback */
|
|
9
|
+
maxRestMs = 40;
|
|
10
|
+
declare const
|
|
11
|
+
/** Rest owed for busy interval */
|
|
12
|
+
restFor: (busyMs: number) => number;
|
|
13
|
+
/** WebGPU device resting after readback */
|
|
14
|
+
declare const throttledDevice: ({ device, pace, }: GpuThrottleParams) => GpuDevice;
|
|
15
|
+
/** Drop device and wasm module */
|
|
16
|
+
declare const releaseDevice: (mod: Awaited<ReturnType<typeof loadLitert>>) => void;
|
|
17
|
+
/** Cache one file per URL */
|
|
6
18
|
declare const cacheModel: (url: string, cache: Cache, signal: AbortSignal | undefined, onProgress: StartLlmParams[`onProgress`]) => Promise<void>;
|
|
7
|
-
/** Map
|
|
19
|
+
/** Map messages to LiteRT turns */
|
|
8
20
|
declare const toLitertMessages: (messages: EngineMessage[], keepMedia?: boolean) => Promise<LitertMessage[]>;
|
|
9
|
-
/** Whether
|
|
21
|
+
/** Whether conversation holds incoming history */
|
|
10
22
|
declare const continuesHistory: (sent: EngineMessage[], history: EngineMessage[]) => boolean;
|
|
11
|
-
/** Stream
|
|
23
|
+
/** Stream LiteRT reply as chunks */
|
|
12
24
|
declare const streamLitert: ({ engine, mod, params, messages, session, }: StreamLitertParams) => AsyncGenerator<EngineChunk>;
|
|
13
|
-
/**
|
|
14
|
-
declare const litertSettings: ({ model, limits, source, mod, }: LitertSettingsParams) => LitertSettings;
|
|
25
|
+
/** Engine settings with vision budget */
|
|
26
|
+
declare const litertSettings: ({ model, limits, contextSize, source, mod, }: LitertSettingsParams) => LitertSettings;
|
|
15
27
|
declare const litertEngine: LlmEngine;
|
|
16
|
-
export { cacheModel, continuesHistory, litertEngine, litertSettings, streamLitert, toLitertMessages, visionTokens, };
|
|
28
|
+
export { cacheModel, continuesHistory, gpuShare, litertEngine, litertSettings, maxRestMs, releaseDevice, restFor, streamLitert, throttledDevice, toLitertMessages, visionTokens, };
|
package/dist/engines/store.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ModelStore, ResumePlan, StoredFilePart, StoredPart } from '../types';
|
|
2
2
|
declare const
|
|
3
|
-
/** Contiguous parts
|
|
3
|
+
/** Contiguous parts until first gap */
|
|
4
4
|
chainParts: (parts: StoredFilePart[]) => StoredFilePart[],
|
|
5
|
-
/** Where
|
|
5
|
+
/** Where response continues parts */
|
|
6
6
|
resumePlan: (response: Response, part: StoredPart) => ResumePlan | undefined,
|
|
7
|
-
/** Whether
|
|
7
|
+
/** Whether store failure disables storage */
|
|
8
8
|
isStoreError: (error: unknown) => boolean;
|
|
9
|
-
/** Create
|
|
9
|
+
/** Create engine resumable file store */
|
|
10
10
|
declare const createModelStore: (dirName: string) => ModelStore;
|
|
11
11
|
export { chainParts, createModelStore, isStoreError, resumePlan, };
|
package/dist/engines/wllama.d.ts
CHANGED
|
@@ -8,19 +8,19 @@ declare const visionLimits: (model: ChatModel) => {
|
|
|
8
8
|
image_max_tokens?: undefined;
|
|
9
9
|
};
|
|
10
10
|
declare const
|
|
11
|
-
/**
|
|
11
|
+
/** CPU file names and URLs */
|
|
12
12
|
cpuFiles: (model: ChatModel) => Array<{
|
|
13
13
|
name: string;
|
|
14
14
|
url: string;
|
|
15
15
|
}>,
|
|
16
|
-
/**
|
|
16
|
+
/** CPU files as stored blobs */
|
|
17
17
|
storedBlobs: ({ model, signal, onProgress, }: {
|
|
18
18
|
model: ChatModel;
|
|
19
19
|
signal?: AbortSignal;
|
|
20
20
|
onProgress: StartLlmParams[`onProgress`];
|
|
21
21
|
}) => Promise<Blob[] | undefined>,
|
|
22
|
-
/** Map
|
|
22
|
+
/** Map messages to wllama turns */
|
|
23
23
|
toWllamaMessages: (messages: EngineMessage[]) => Promise<WllamaMessage[]>,
|
|
24
|
-
/** Start
|
|
24
|
+
/** Start CPU runtime engine entry */
|
|
25
25
|
startLLM: ({ model, limits, onProgress, signal, logging, assets: overrides, }: StartLlmParams) => Promise<LlmRuntime>, wllamaEngine: LlmEngine;
|
|
26
26
|
export { cpuFiles, startLLM, storedBlobs, toWllamaMessages, visionLimits, wllamaEngine, };
|
package/dist/enums.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Author of a chat message */
|
|
2
2
|
declare enum LlmRole {
|
|
3
3
|
system = "system",
|
|
4
4
|
user = "user",
|
|
5
5
|
assistant = "assistant"
|
|
6
6
|
}
|
|
7
|
-
/** Assistant availability
|
|
7
|
+
/** Assistant availability from engine */
|
|
8
8
|
declare enum ChatStatus {
|
|
9
9
|
online = 0,
|
|
10
10
|
away = 1,
|
|
@@ -18,23 +18,22 @@ declare enum LlmStatus {
|
|
|
18
18
|
error = 3,
|
|
19
19
|
unsupported = 4
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
21
|
+
/** Engine running the model */
|
|
22
22
|
declare enum LlmBackend {
|
|
23
23
|
cpu = "cpu",
|
|
24
24
|
gpu = "gpu",
|
|
25
25
|
none = "none"
|
|
26
26
|
}
|
|
27
|
-
/** Download or load
|
|
27
|
+
/** Download or load phase */
|
|
28
28
|
declare enum LlmPhase {
|
|
29
29
|
download = "download",
|
|
30
30
|
load = "load"
|
|
31
31
|
}
|
|
32
|
-
/** Catalog ids of
|
|
32
|
+
/** Catalog ids of on-device models */
|
|
33
33
|
declare enum ChatModelId {
|
|
34
34
|
qwen3_vl_2b = "qwen3-vl-2b",
|
|
35
35
|
qwen3_vl_2b_instruct = "qwen3-vl-2b-instruct",
|
|
36
36
|
qwen3_vl_2b_instruct_q3 = "qwen3-vl-2b-instruct-q3",
|
|
37
|
-
gemma4_e2b = "gemma4-e2b",
|
|
38
37
|
gemma4_e2b_limited = "gemma4-e2b-limited"
|
|
39
38
|
}
|
|
40
39
|
/** Built-in tools the package ships */
|
|
@@ -43,7 +42,7 @@ declare enum BuiltinTool {
|
|
|
43
42
|
calculate = "calculate",
|
|
44
43
|
currency = "currency"
|
|
45
44
|
}
|
|
46
|
-
/**
|
|
45
|
+
/** Provider behind the websearch tool */
|
|
47
46
|
declare enum WebSearchProvider {
|
|
48
47
|
wikipedia = "wikipedia",
|
|
49
48
|
duckduckgo = "duckduckgo"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { clearModelCache, createChat, preloadModel } from './chat';
|
|
2
|
-
export { describeImages, describeModelId, describeTranslated } from './describe';
|
|
2
|
+
export { describeImages, describeModelId, describeTranslated, imageReplyTokens } from './describe';
|
|
3
|
+
export { gpuAdapter } from './models';
|
|
3
4
|
export { builtinTools, calculateTool, currencyTool, webSearchTool, } from './tools';
|
|
4
5
|
export { LlmRole, ChatStatus, LlmStatus, LlmBackend, LlmPhase, ChatModelId, BuiltinTool, WebSearchProvider, } from './enums';
|
|
5
6
|
export type { ChatMessage, LlmLimits, ChatStatusSnapshot, ChatInput, ChatPreloadInput, CancelChat, DescribeImagesInput, DescribeTranslatedInput, ImageDescription, WllamaAssets, ChatTool, ChatToolCall, ChatToolResult, ChatToolSchema, ChatToolValue, WebSearchConfig, WebSearchResult, } from './types';
|
package/dist/log.d.ts
CHANGED
package/dist/models.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { ChatModelId } from './enums';
|
|
2
2
|
import type { ChatModel, MobileNavigator } from './types';
|
|
3
3
|
declare const llmModels: ChatModel[],
|
|
4
|
-
/**
|
|
4
|
+
/** CPU context window, 8k tokens */
|
|
5
5
|
cpuContextWindow = 8192, // max 262_400
|
|
6
|
-
/** CPU window
|
|
6
|
+
/** Phone CPU window, 4096 tokens */
|
|
7
7
|
mobileCpuContextWindow = 4096, // max 32_768
|
|
8
|
-
/**
|
|
9
|
-
litertContextWindow =
|
|
10
|
-
/**
|
|
8
|
+
/** GPU context window, 32k tokens */
|
|
9
|
+
litertContextWindow = 32768, // max 32_768
|
|
10
|
+
/** Phone GPU window, 16k tokens */
|
|
11
|
+
mobileLitertContextWindow = 16384, // max 32_768
|
|
12
|
+
/** Whether this client is mobile */
|
|
11
13
|
mobileDevice: (nav?: MobileNavigator) => boolean,
|
|
12
|
-
/**
|
|
13
|
-
deviceModelId: (id?: ChatModelId, mobile?: boolean) => ChatModelId | undefined,
|
|
14
|
-
/** Look up a catalog entry by id */
|
|
14
|
+
/** Find catalog entry by id */
|
|
15
15
|
findLlmModel: (id?: string) => ChatModel | undefined,
|
|
16
|
-
/** Whether
|
|
16
|
+
/** Whether browser has WebGPU adapter */
|
|
17
17
|
gpuAdapter: () => Promise<boolean>,
|
|
18
|
-
/** Default model,
|
|
18
|
+
/** Default model, GPU when available */
|
|
19
19
|
defaultLlmModel: () => Promise<ChatModelId | undefined>,
|
|
20
|
-
/** Resolve
|
|
20
|
+
/** Resolve requested model or default */
|
|
21
21
|
resolveLlmModel: (id?: ChatModelId) => Promise<ChatModel | undefined>,
|
|
22
22
|
/** Whether a model accepts images */
|
|
23
23
|
supportsImages: (model: ChatModel) => boolean,
|
|
24
24
|
/** Whether a model accepts audio */
|
|
25
25
|
supportsAudio: (model: ChatModel) => boolean;
|
|
26
|
-
export { llmModels, cpuContextWindow, mobileCpuContextWindow, litertContextWindow,
|
|
26
|
+
export { llmModels, cpuContextWindow, mobileCpuContextWindow, litertContextWindow, mobileLitertContextWindow, mobileDevice, findLlmModel, gpuAdapter, defaultLlmModel, resolveLlmModel, supportsImages, supportsAudio, };
|