@hosty-sdk/app 0.30.0 → 0.31.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/dist/providers-server.d.ts +4 -1
- package/dist/providers-server.js +14 -0
- package/dist/providers.d.ts +24 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssistantClient } from "@hosty-sdk/app/assistant";
|
|
2
|
-
import { type AppPermissionState, type ProviderDescriptor, type ProviderInvocation, type ProviderKind, type SpeechCapabilities, type SpeechResult } from "@hosty-sdk/app/providers";
|
|
2
|
+
import { type AppPermissionState, type ProviderDescriptor, type ProviderInvocation, type ProviderKind, type SpeechCapabilities, type SpeechResult, type TranslationRequest, type TranslationResult, type TranslationCapabilities } from "@hosty-sdk/app/providers";
|
|
3
3
|
export type ProviderServerOptions = {
|
|
4
4
|
appId?: string;
|
|
5
5
|
coreOrigin?: string;
|
|
@@ -23,6 +23,9 @@ export declare class ProviderClient {
|
|
|
23
23
|
language?: string;
|
|
24
24
|
signal?: AbortSignal;
|
|
25
25
|
}): Promise<SpeechResult>;
|
|
26
|
+
translationCapabilities(provider: Pick<ProviderDescriptor, "appId" | "key">, signal?: AbortSignal): Promise<TranslationCapabilities>;
|
|
27
|
+
/** Translate text or Markdown through the explicitly selected provider; never retries or falls back. */
|
|
28
|
+
translate(provider: Pick<ProviderDescriptor, "appId" | "key">, input: TranslationRequest, signal?: AbortSignal): Promise<TranslationResult>;
|
|
26
29
|
/** User-attributed requests preserve the assistant's existing handoff and dispatch policy. */
|
|
27
30
|
assistant(provider: Pick<ProviderDescriptor, "appId" | "key"> & {
|
|
28
31
|
installationId?: string | null;
|
package/dist/providers-server.js
CHANGED
|
@@ -54,6 +54,20 @@ export class ProviderClient {
|
|
|
54
54
|
return read(await fetch(url, { method: "POST", redirect: "error", signal,
|
|
55
55
|
headers: { authorization: `Bearer ${binding.token}`, "content-type": audio.type || "audio/wav" }, body: audio }));
|
|
56
56
|
}
|
|
57
|
+
async translationCapabilities(provider, signal) {
|
|
58
|
+
const binding = await this.connect({ ...provider, kind: "translation" }, signal);
|
|
59
|
+
return read(await fetch(`${binding.url}/capabilities`, { redirect: "error", signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(10_000)]) : AbortSignal.timeout(10_000), headers: { authorization: `Bearer ${binding.token}` } }));
|
|
60
|
+
}
|
|
61
|
+
/** Translate text or Markdown through the explicitly selected provider; never retries or falls back. */
|
|
62
|
+
async translate(provider, input, signal) {
|
|
63
|
+
const deadline = signal ? AbortSignal.any([signal, AbortSignal.timeout(610_000)]) : AbortSignal.timeout(610_000);
|
|
64
|
+
const binding = await this.connect({ ...provider, kind: "translation" }, deadline);
|
|
65
|
+
const result = await read(await fetch(`${binding.url}/translations`, { method: "POST", redirect: "error", signal: deadline,
|
|
66
|
+
headers: { authorization: `Bearer ${binding.token}`, "content-type": "application/json" }, body: JSON.stringify(input) }));
|
|
67
|
+
if (typeof result.text !== "string" || result.targetLanguage !== input.targetLanguage || result.sourceLanguage !== (input.sourceLanguage ?? "auto"))
|
|
68
|
+
throw new ProviderError("provider_response_invalid", "Invalid translation response.", 502);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
57
71
|
/** User-attributed requests preserve the assistant's existing handoff and dispatch policy. */
|
|
58
72
|
async assistant(provider, userToken) {
|
|
59
73
|
const target = { ...provider, kind: "assistant" };
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Provider categories supported by Core. Agent execution is intentionally not part of this contract. */
|
|
2
|
-
export type ProviderKind = "speech-to-text" | "assistant";
|
|
2
|
+
export type ProviderKind = "speech-to-text" | "assistant" | "translation";
|
|
3
3
|
export type ProviderDescriptor = {
|
|
4
4
|
appId: string;
|
|
5
5
|
displayName: string;
|
|
@@ -48,6 +48,29 @@ export type SpeechCapabilities = {
|
|
|
48
48
|
backend: string;
|
|
49
49
|
ready: boolean;
|
|
50
50
|
};
|
|
51
|
+
export type TranslationRequest = {
|
|
52
|
+
text: string;
|
|
53
|
+
targetLanguage: string;
|
|
54
|
+
sourceLanguage?: string;
|
|
55
|
+
format?: "text" | "markdown";
|
|
56
|
+
};
|
|
57
|
+
export type TranslationResult = {
|
|
58
|
+
text: string;
|
|
59
|
+
targetLanguage: string;
|
|
60
|
+
sourceLanguage: string;
|
|
61
|
+
};
|
|
62
|
+
export type TranslationCapabilities = {
|
|
63
|
+
version: 1;
|
|
64
|
+
formats: string[];
|
|
65
|
+
maxCharacters: number;
|
|
66
|
+
maxSegmentCharacters: number;
|
|
67
|
+
maxBytes: number;
|
|
68
|
+
maxOutputBytes: number;
|
|
69
|
+
timeoutSeconds: number;
|
|
70
|
+
backend: string;
|
|
71
|
+
ready: boolean;
|
|
72
|
+
reason?: string;
|
|
73
|
+
};
|
|
51
74
|
/** Errors retain Core/provider codes so consumers can distinguish denial from unavailable service. */
|
|
52
75
|
export declare class ProviderError extends Error {
|
|
53
76
|
readonly code: string;
|
package/package.json
CHANGED