@hosty-sdk/app 0.52.0 → 0.53.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 CHANGED
@@ -303,6 +303,16 @@ their existing behavior. Validate the selected provider's duration/byte capabili
303
303
  credentials and the acting user's access. It does not expose general agent execution.
304
304
  See [Provider consumption](../../docs/features/provider-consumption/feature.md) for the full contract.
305
305
 
306
+ ### Named implementations and read-aloud
307
+
308
+ Call `listImplementations("speech-to-text")` or `listImplementations("text-to-speech")` to list both
309
+ static and named entries. Keep the installation, key and implementation ID with each choice. The
310
+ `displayName` is the current human-readable label. Pass the selection to `speechCapabilities`
311
+ and `transcribe`, or to `textToSpeechCapabilities` and `synthesize(selected, { text }, signal)`.
312
+ Synthesis returns a streaming fetch Response. Abort or cancel its body to stop the request.
313
+ The provider backend publishes with `publishImplementations` and resolves the exact implementation
314
+ from `validate` on each request. See the [app manifest guide](../../skills/hosty-app-skill/references/app-manifest.md#named-provider-implementations).
315
+
306
316
  ## Tasks And Execution Providers
307
317
 
308
318
  Core 0.159.0 and SDK 0.36.0 support independent `tasks` and `task-executor` categories. Request
@@ -8,7 +8,8 @@ const segment = (id) => {
8
8
  throw new AgentApiError("invalid_input", "A bounded opaque resource ID is required.", 400);
9
9
  return encodeURIComponent(id);
10
10
  };
11
- const sameProvider = (a, b) => a.appId === b.appId && a.installationId === b.installationId && a.key === b.key;
11
+ const sameProvider = (a, b) => a.appId === b.appId && a.installationId === b.installationId && a.key === b.key
12
+ && (a.implementationId ?? null) === (b.implementationId ?? null);
12
13
  /** Preparing once lets an application persist exactly the bytes it must reuse after an uncertain delivery. */
13
14
  export function prepareAgentRequest(operation, method, path, input, metadata = {}) {
14
15
  const body = JSON.stringify(input);
@@ -22,7 +22,7 @@ const historyObservation = {
22
22
  object({ kind: { const: "event" }, event: ref("Event"), cursor: text(8192) })] },
23
23
  };
24
24
  export const AGENT_SCHEMAS = {
25
- ProviderRef: object(refProperties),
25
+ ProviderRef: object({ ...refProperties, implementationId: { anyOf: [text(128), { type: "null" }] } }, Object.keys(refProperties)),
26
26
  QualifiedRef: object({ provider: ref("ProviderRef"), id }),
27
27
  Instruction: object({ id: text(128), text: { type: "string", maxLength: 262144 } }),
28
28
  Skill: object({ skillId: digest, expectedDigest: digest }, ["skillId"]),
@@ -20,7 +20,9 @@ function strings(value, max = 128, width = 256) {
20
20
  fail("Selections require distinct bounded strings.");
21
21
  }
22
22
  function provider(value) {
23
- shape(value, ["appId", "installationId", "key"], "provider reference");
23
+ shape(value, ["appId", "installationId", "key", "implementationId"], "provider reference");
24
+ if (value.implementationId != null && !bounded(value.implementationId, 128))
25
+ fail("Invalid named implementation ID.");
24
26
  if (![value.appId, value.installationId, value.key].every(v => bounded(v)))
25
27
  fail("An installation-qualified provider reference is required.");
26
28
  }
@@ -3,6 +3,7 @@ export type ProviderRef = {
3
3
  appId: string;
4
4
  installationId: string;
5
5
  key: string;
6
+ implementationId?: string | null;
6
7
  };
7
8
  export type ConversationRef = {
8
9
  provider: ProviderRef;
@@ -60,6 +60,7 @@ export declare function resolveAssistantPresentation(provider: ProviderDescripto
60
60
  appId: string;
61
61
  installationId: string;
62
62
  key: string;
63
+ implementationId?: string | null;
63
64
  };
64
65
  }): {
65
66
  target: PanelTarget | null;
package/dist/assistant.js CHANGED
@@ -48,7 +48,8 @@ export function resolveAssistantPresentation(provider, result, options) {
48
48
  const expected = options.expectedProvider;
49
49
  if (!provider.installationId)
50
50
  throw new AssistantError("unsupported_core", "Update Core to identify assistant installations.", 409);
51
- if (provider.appId !== expected.appId || provider.key !== expected.key || provider.installationId !== expected.installationId)
51
+ if (provider.appId !== expected.appId || provider.key !== expected.key || provider.installationId !== expected.installationId
52
+ || (provider.implementationId ?? null) !== (expected.implementationId ?? null))
52
53
  throw new AssistantError("provider_changed", "The original assistant installation is no longer available.", 409);
53
54
  try {
54
55
  resolveAssistantDestination(result.open, provider.uiSurfaces ?? []);
@@ -1,6 +1,6 @@
1
1
  import type { HistoryExportGrant, HistoryExportAcknowledge, HistoryExportQuery, HistoryExportSnapshot, HistoryChangePage } from "./history.js";
2
2
  import { AssistantClient } from "@hosty-sdk/app/assistant";
3
- import { type AppPermissionState, type ProviderDescriptor, type ProviderInvocation, type ProviderKind, type MediatedProviderInvocation, type MediatedProviderRequest, type SpeechCapabilities, type SpeechResult, type TranslationRequest, type TranslationResult, type TranslationCapabilities } from "@hosty-sdk/app/providers";
3
+ import { type AppPermissionState, type ProviderDescriptor, type ProviderInvocation, type ProviderKind, type MediatedProviderInvocation, type MediatedProviderRequest, type SpeechCapabilities, type SpeechResult, type TranslationRequest, type TranslationResult, type TranslationCapabilities, type ProviderSelection, type ProviderImplementationSnapshot, type TextToSpeechCapabilities, type SpeechSynthesisRequest } from "@hosty-sdk/app/providers";
4
4
  export type ProviderServerOptions = {
5
5
  appId?: string;
6
6
  coreOrigin?: string;
@@ -32,25 +32,32 @@ export declare class ProviderClient {
32
32
  historyExportChanges(input: HistoryExportQuery, signal?: AbortSignal): Promise<HistoryChangePage>;
33
33
  permissions(signal?: AbortSignal): Promise<AppPermissionState>;
34
34
  list(kind: ProviderKind, signal?: AbortSignal): Promise<ProviderDescriptor[]>;
35
+ /** Discover static and named implementations. Retain the complete selection across calls. */
36
+ listImplementations(kind: ProviderKind, signal?: AbortSignal): Promise<ProviderDescriptor[]>;
37
+ /** Replace this installation's complete snapshot for one reviewed interface entry. */
38
+ publishImplementations(kind: ProviderKind, key: string, snapshot: ProviderImplementationSnapshot, signal?: AbortSignal): Promise<{
39
+ revision: number;
40
+ }>;
35
41
  private connect;
36
- speechCapabilities(provider: Pick<ProviderDescriptor, "appId" | "key">, signal?: AbortSignal): Promise<SpeechCapabilities>;
37
- transcribe(provider: Pick<ProviderDescriptor, "appId" | "key">, audio: Blob, options?: {
42
+ speechCapabilities(provider: ProviderSelection, signal?: AbortSignal): Promise<SpeechCapabilities>;
43
+ transcribe(provider: ProviderSelection, audio: Blob, options?: {
38
44
  language?: string;
39
45
  signal?: AbortSignal; /** Total deadline, 1–930000 ms; defaults to five minutes. */
40
46
  timeoutMs?: number;
41
47
  }): Promise<SpeechResult>;
42
- translationCapabilities(provider: Pick<ProviderDescriptor, "appId" | "key">, signal?: AbortSignal, options?: {
48
+ textToSpeechCapabilities(provider: ProviderSelection, signal?: AbortSignal): Promise<TextToSpeechCapabilities>;
49
+ /** Stream 24 kHz mono signed 16-bit little-endian PCM. Cancel the signal or response body to stop. */
50
+ synthesize(provider: ProviderSelection, input: SpeechSynthesisRequest, signal?: AbortSignal): Promise<Response>;
51
+ translationCapabilities(provider: ProviderSelection, signal?: AbortSignal, options?: {
43
52
  connection: {
44
53
  id: string;
45
54
  revision: string;
46
55
  };
47
56
  }): Promise<TranslationCapabilities>;
48
57
  /** Translate text or Markdown through the explicitly selected provider; never retries or falls back. */
49
- translate(provider: Pick<ProviderDescriptor, "appId" | "key">, input: TranslationRequest, signal?: AbortSignal): Promise<TranslationResult>;
58
+ translate(provider: ProviderSelection, input: TranslationRequest, signal?: AbortSignal): Promise<TranslationResult>;
50
59
  /** User-attributed requests preserve the assistant's existing handoff and dispatch policy. */
51
- assistant(provider: Pick<ProviderDescriptor, "appId" | "key"> & {
52
- installationId?: string | null;
53
- }, userToken: () => Promise<string>): Promise<AssistantClient>;
60
+ assistant(provider: ProviderSelection, userToken: () => Promise<string>): Promise<AssistantClient>;
54
61
  /** Bounded task protocol transport. The selected installation is checked on every operation. */
55
62
  taskRequest<T>(provider: import("./tasks.js").TaskProviderRef, kind: "tasks" | "task-executor", route: string, method: string, input?: unknown, userToken?: () => Promise<string>, signal?: AbortSignal): Promise<T>;
56
63
  /** Validate an operation-bound Core credential against this exact request. Source ACL checks remain mandatory. */
@@ -48,12 +48,25 @@ export class ProviderClient {
48
48
  async list(kind, signal) {
49
49
  return (await this.coreRequest(`/providers/${kind}`, undefined, signal)).providers;
50
50
  }
51
+ /** Discover static and named implementations. Retain the complete selection across calls. */
52
+ async listImplementations(kind, signal) {
53
+ return (await this.coreRequest(`/providers/${kind}?named=true`, undefined, signal)).providers;
54
+ }
55
+ /** Replace this installation's complete snapshot for one reviewed interface entry. */
56
+ publishImplementations(kind, key, snapshot, signal) {
57
+ return this.coreRequest(`/providers/${kind}/implementations`, { key, revision: snapshot.revision, implementations: snapshot.implementations }, signal);
58
+ }
51
59
  async connect(provider, signal, userToken) {
52
- const issued = await this.coreRequest(`/providers/${provider.kind}/token`, { providerAppId: provider.appId, key: provider.key }, signal, userToken);
60
+ if (provider.implementationId != null && !provider.installationId)
61
+ throw new ProviderError("provider_selection_invalid", "A named implementation requires an installation.", 400);
62
+ const issued = await this.coreRequest(`/providers/${provider.kind}/token`, { providerAppId: provider.appId, key: provider.key, installationId: provider.installationId, implementationId: provider.implementationId }, signal, userToken);
63
+ if (issued.provider.appId !== provider.appId || issued.provider.kind !== provider.kind || issued.provider.key !== provider.key
64
+ || (issued.provider.implementationId ?? null) !== (provider.implementationId ?? null))
65
+ throw new ProviderError("provider_changed", "The selected provider binding changed.", 409);
53
66
  if (issued.provider.version !== 1 || !issued.provider.url)
54
67
  throw new ProviderError("provider_incompatible", "This provider does not support interface version 1.", 409);
55
68
  if (provider.installationId && issued.provider.installationId !== provider.installationId)
56
- throw new ProviderError("provider_changed", "The selected assistant installation changed. Start a new discussion explicitly.", 409);
69
+ throw new ProviderError("provider_changed", "The selected provider installation changed. Select it again.", 409);
57
70
  const url = new URL(issued.provider.url);
58
71
  if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
59
72
  throw new ProviderError("provider_url_invalid", "Invalid provider endpoint.", 409);
@@ -92,6 +105,30 @@ export class ProviderClient {
92
105
  await dispatcher.close();
93
106
  }
94
107
  }
108
+ async textToSpeechCapabilities(provider, signal) {
109
+ const binding = await this.connect({ ...provider, kind: "text-to-speech" }, signal);
110
+ const deadline = AbortSignal.timeout(10_000);
111
+ return read(await fetch(`${binding.url}/capabilities`, { redirect: "error", signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
112
+ headers: { authorization: `Bearer ${binding.token}` } }));
113
+ }
114
+ /** Stream 24 kHz mono signed 16-bit little-endian PCM. Cancel the signal or response body to stop. */
115
+ async synthesize(provider, input, signal) {
116
+ if (typeof input.text !== "string" || !input.text.trim() || input.text.length > 4000)
117
+ throw new ProviderError("speech_text_invalid", "Provide between 1 and 4000 UTF-16 code units of text.", 400);
118
+ const timeout = AbortSignal.timeout(300_000);
119
+ const deadline = signal ? AbortSignal.any([signal, timeout]) : timeout;
120
+ const binding = await this.connect({ ...provider, kind: "text-to-speech" }, deadline);
121
+ const response = await fetch(`${binding.url}/speech`, { method: "POST", redirect: "error", signal: deadline,
122
+ headers: { authorization: `Bearer ${binding.token}`, "content-type": "application/json", accept: "audio/pcm" },
123
+ body: JSON.stringify({ text: input.text }) });
124
+ if (!response.ok)
125
+ await read(response);
126
+ if (!response.body || !/^audio\/pcm\s*;\s*rate=24000\s*$/i.test(response.headers.get("content-type") ?? "")) {
127
+ await response.body?.cancel();
128
+ throw new ProviderError("provider_response_invalid", "Expected a 24 kHz PCM audio stream.", 502);
129
+ }
130
+ return response;
131
+ }
95
132
  async translationCapabilities(provider, signal, options) {
96
133
  const connection = options?.connection;
97
134
  if (options && (!connection || typeof connection.id !== "string" || !connection.id || connection.id.length > 200
@@ -1,5 +1,5 @@
1
1
  /** Provider categories supported by Core. Task execution does not expose model/profile configuration. */
2
- export type ProviderKind = "agent" | "speech-to-text" | "assistant" | "translation" | "tasks" | "task-executor" | "conversation-history" | "agent-sessions";
2
+ export type ProviderKind = "agent" | "speech-to-text" | "text-to-speech" | "assistant" | "translation" | "tasks" | "task-executor" | "conversation-history" | "agent-sessions";
3
3
  export type ProviderDescriptor = {
4
4
  appId: string;
5
5
  displayName: string;
@@ -19,6 +19,19 @@ export type ProviderDescriptor = {
19
19
  }> | null;
20
20
  /** Opaque Core installation identity; compare for equality, never parse. */
21
21
  installationId?: string | null;
22
+ /** Opaque provider-owned ID, scoped to this installation, kind and declared key. */
23
+ implementationId?: string | null;
24
+ implementationName?: string | null;
25
+ };
26
+ export type ProviderSelection = Pick<ProviderDescriptor, "appId" | "key" | "installationId" | "implementationId">;
27
+ export type ProviderImplementation = {
28
+ id: string;
29
+ displayName: string;
30
+ available: boolean;
31
+ };
32
+ export type ProviderImplementationSnapshot = {
33
+ revision: number;
34
+ implementations: ProviderImplementation[];
22
35
  };
23
36
  export type AppPermissionState = {
24
37
  required: string[];
@@ -35,6 +48,7 @@ export type ProviderInvocation = {
35
48
  hostRole: string | null;
36
49
  kind: ProviderKind;
37
50
  key: string;
51
+ implementationId?: string | null;
38
52
  };
39
53
  /** Core-mediated v2 invocations carry the original principal; direct clients have no app identity. */
40
54
  export type MediatedProviderInvocation = {
@@ -49,6 +63,7 @@ export type MediatedProviderInvocation = {
49
63
  principalId: string;
50
64
  kind: ProviderKind;
51
65
  key: string;
66
+ implementationId?: string | null;
52
67
  operation: string;
53
68
  resourceIds: string[];
54
69
  taskDispatch?: TaskDispatchRef | null;
@@ -84,6 +99,16 @@ export type SpeechCapabilities = {
84
99
  backend: string;
85
100
  ready: boolean;
86
101
  };
102
+ export type TextToSpeechCapabilities = {
103
+ version: 1;
104
+ mediaTypes: string[];
105
+ maxCharacters: number;
106
+ backend: string;
107
+ ready: boolean;
108
+ };
109
+ export type SpeechSynthesisRequest = {
110
+ text: string;
111
+ };
87
112
  export type TranslationRequest = {
88
113
  text: string;
89
114
  targetLanguage: string;
@@ -13,7 +13,8 @@ export class TaskClient {
13
13
  return this.providers.taskRequest(this.provider, "tasks", route, method, input, this.userToken, signal);
14
14
  }
15
15
  id(ref) {
16
- if (ref.appId !== this.provider.appId || ref.installationId !== this.provider.installationId || ref.key !== this.provider.key)
16
+ if (ref.appId !== this.provider.appId || ref.installationId !== this.provider.installationId || ref.key !== this.provider.key
17
+ || (ref.implementationId ?? null) !== (this.provider.implementationId ?? null))
17
18
  throw new Error("The task belongs to another provider installation.");
18
19
  return encodeURIComponent(ref.id);
19
20
  }
package/dist/tasks.d.ts CHANGED
@@ -3,6 +3,7 @@ export type TaskProviderRef = {
3
3
  appId: string;
4
4
  installationId: string;
5
5
  key: string;
6
+ implementationId?: string | null;
6
7
  };
7
8
  export type TaskRef = TaskProviderRef & {
8
9
  id: string;
package/dist/tasks.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export const taskStatuses = ["Draft", "Ready", "InProgress", "Blocked", "Done", "Cancelled"];
2
2
  export const taskExecutionTerminal = (state) => ["completed", "failed", "cancelled", "interrupted"].includes(state);
3
3
  /** Collision-free opaque reference for cross-provider links and filters; grants no task access. */
4
- export const taskReferenceKey = (ref) => JSON.stringify([ref.appId, ref.installationId, ref.key, ref.id]);
4
+ export const taskReferenceKey = (ref) => JSON.stringify(ref.implementationId ? [ref.appId, ref.installationId, ref.key, ref.id, ref.implementationId] : [ref.appId, ref.installationId, ref.key, ref.id]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hosty-sdk/app",
3
- "version": "0.52.0",
3
+ "version": "0.53.0",
4
4
  "description": "Hosty app auth: session state machine, recovery bridge, Core revalidation, and the embedder responder.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -20,6 +20,18 @@
20
20
  "type": "string",
21
21
  "minLength": 1,
22
22
  "maxLength": 256
23
+ },
24
+ "implementationId": {
25
+ "anyOf": [
26
+ {
27
+ "type": "string",
28
+ "minLength": 1,
29
+ "maxLength": 128
30
+ },
31
+ {
32
+ "type": "null"
33
+ }
34
+ ]
23
35
  }
24
36
  },
25
37
  "required": [
@@ -3129,6 +3129,18 @@
3129
3129
  "type": "string",
3130
3130
  "minLength": 1,
3131
3131
  "maxLength": 256
3132
+ },
3133
+ "implementationId": {
3134
+ "anyOf": [
3135
+ {
3136
+ "type": "string",
3137
+ "minLength": 1,
3138
+ "maxLength": 128
3139
+ },
3140
+ {
3141
+ "type": "null"
3142
+ }
3143
+ ]
3132
3144
  }
3133
3145
  },
3134
3146
  "required": [