@alia.onl/sdk 15.8.0 → 19.1.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +262 -13
  2. package/README.md +223 -151
  3. package/package.json +16 -6
  4. package/src/animations.ts +0 -1
  5. package/src/components/AliaAskProvider.tsx +127 -0
  6. package/src/components/AliaChatContent.tsx +604 -392
  7. package/src/components/AliaChatHeader.tsx +14 -38
  8. package/src/components/AliaChatScreen.tsx +56 -31
  9. package/src/components/AliaChatSheet.tsx +110 -36
  10. package/src/components/AliaComposer.tsx +1 -1
  11. package/src/components/AliaParticipants.tsx +202 -0
  12. package/src/components/AliaParticipantsHeader.tsx +60 -0
  13. package/src/components/AliaSharedConversation.tsx +86 -0
  14. package/src/components/AliaWelcomeMessage.tsx +18 -5
  15. package/src/components/Image.tsx +12 -0
  16. package/src/components/Markdown.tsx +498 -14
  17. package/src/components/PlanPreviewCard.tsx +7 -49
  18. package/src/components/ReplyMarkdown.tsx +359 -0
  19. package/src/components/RichBlocks.tsx +195 -0
  20. package/src/components/canvas/CanvasComponent.tsx +59 -0
  21. package/src/components/canvas/ChartRenderer.tsx +73 -0
  22. package/src/components/canvas/CodeRenderer.tsx +24 -0
  23. package/src/components/canvas/FormRenderer.tsx +101 -0
  24. package/src/components/canvas/MarkdownRenderer.tsx +14 -0
  25. package/src/components/canvas/TableRenderer.tsx +47 -0
  26. package/src/components/thought/FilesAndSources.tsx +120 -0
  27. package/src/components/thought/ThoughtPanel.tsx +417 -0
  28. package/src/components/thought/ToolStep.tsx +141 -0
  29. package/src/components/thread/AgentResultCard.tsx +125 -0
  30. package/src/components/thread/AgentTaskCard.tsx +127 -0
  31. package/src/components/thread/AliaThread.tsx +401 -0
  32. package/src/components/thread/MessageBlockBoundary.tsx +78 -0
  33. package/src/components/thread/NewConversationOffer.tsx +54 -0
  34. package/src/components/thread/ThreadRow.tsx +458 -0
  35. package/src/components/thread/ThreadSearch.tsx +129 -0
  36. package/src/components/thread/ToolResultCard.tsx +254 -0
  37. package/src/components/thread/TurnMenu.tsx +54 -0
  38. package/src/components/thread/TurnStatusLine.tsx +34 -0
  39. package/src/components/voice/AliaVoiceCall.tsx +21 -0
  40. package/src/components/voice/VoiceControls.tsx +2 -28
  41. package/src/components/voice/VoiceSession.tsx +39 -11
  42. package/src/hooks/useAliaActivity.ts +2 -2
  43. package/src/hooks/useAtBottom.ts +51 -0
  44. package/src/hooks/useAttachMenu.ts +94 -0
  45. package/src/hooks/useChatComposer.ts +299 -0
  46. package/src/hooks/useChatVoice.ts +129 -0
  47. package/src/hooks/useDocumentPicker.ts +3 -29
  48. package/src/hooks/useFailedTurnToast.ts +43 -0
  49. package/src/hooks/useMessageVote.ts +50 -0
  50. package/src/hooks/useOpenThought.ts +79 -0
  51. package/src/hooks/usePendingQuestions.ts +2 -2
  52. package/src/hooks/useReadAloud.ts +92 -0
  53. package/src/hooks/useShareHandler.ts +24 -0
  54. package/src/hooks/useSoundEffects.ts +1 -1
  55. package/src/hooks/useThoughtScope.ts +59 -0
  56. package/src/hooks/useThreadRows.ts +145 -0
  57. package/src/hooks/useThreadView.ts +68 -0
  58. package/src/hooks/useTimelineWindow.ts +256 -0
  59. package/src/hooks/useVoiceLauncher.ts +180 -0
  60. package/src/hooks/useVoiceRoom.ts +4 -4
  61. package/src/index.ts +43 -29
  62. package/src/lib/activity-store.ts +1 -1
  63. package/src/lib/add-menu.ts +7 -0
  64. package/src/lib/call-thread.ts +33 -0
  65. package/src/lib/citations.ts +79 -2
  66. package/src/lib/clipboard.ts +23 -0
  67. package/src/lib/content-utils.ts +10 -0
  68. package/src/lib/copy-en.ts +284 -0
  69. package/src/lib/copy.ts +32 -0
  70. package/src/lib/document-picker.ts +31 -0
  71. package/src/lib/flights.ts +22 -13
  72. package/src/lib/focus-return.ts +66 -0
  73. package/src/lib/keyboard.native.tsx +19 -0
  74. package/src/lib/keyboard.tsx +9 -0
  75. package/src/lib/labels.tsx +69 -17
  76. package/src/lib/participants.ts +86 -0
  77. package/src/lib/power-level-options.ts +66 -0
  78. package/src/lib/questions.ts +2 -2
  79. package/src/lib/task-labels.ts +4 -4
  80. package/src/lib/tool-call-status.ts +1 -1
  81. package/src/lib/tool-icons.ts +36 -0
  82. package/src/lib/tool-renderers.tsx +48 -0
  83. package/src/lib/turn-state.ts +2 -2
  84. package/src/lib/voice-call-request.ts +49 -0
  85. package/src/lib/voice-call.ts +98 -35
  86. package/src/lib/voice-controls-labels.ts +31 -0
  87. package/src/lib/voice-protocol.ts +34 -15
  88. package/src/lib/work-log.ts +6 -6
  89. package/src/runtime/agents.ts +151 -0
  90. package/src/runtime/api.ts +141 -0
  91. package/src/runtime/app-assertion.ts +53 -0
  92. package/src/runtime/attachment-utils.ts +96 -0
  93. package/src/runtime/composer-draft-store.ts +270 -0
  94. package/src/runtime/config.tsx +186 -0
  95. package/src/runtime/conversation-store.ts +49 -0
  96. package/src/runtime/conversations.ts +557 -0
  97. package/src/runtime/error-utils.ts +104 -0
  98. package/src/runtime/host-tools.ts +140 -0
  99. package/src/runtime/index.ts +113 -0
  100. package/src/runtime/message-history.ts +124 -0
  101. package/src/runtime/model.ts +39 -0
  102. package/src/runtime/oxy-files.ts +37 -0
  103. package/src/runtime/power-levels.ts +66 -0
  104. package/src/runtime/query-keys.ts +34 -0
  105. package/src/runtime/random-uuid.ts +25 -0
  106. package/src/runtime/routes.ts +51 -0
  107. package/src/runtime/sharing.ts +165 -0
  108. package/src/runtime/sse-frame-reader.ts +88 -0
  109. package/src/runtime/stream-events.ts +146 -0
  110. package/src/runtime/stream-outcome.ts +21 -0
  111. package/src/runtime/thought-store.ts +103 -0
  112. package/src/runtime/thread/agent-activity.ts +261 -0
  113. package/src/runtime/thread/automation-labels.ts +79 -0
  114. package/src/runtime/thread/conversation-export.ts +135 -0
  115. package/src/runtime/thread/message-days.ts +120 -0
  116. package/src/runtime/thread/message-processor.ts +93 -0
  117. package/src/runtime/thread/task-utils.ts +11 -0
  118. package/src/runtime/thread/thought-utils.ts +752 -0
  119. package/src/runtime/thread/thread-history.ts +139 -0
  120. package/src/runtime/thread/timeline.ts +202 -0
  121. package/src/runtime/thread/title-tags.ts +8 -0
  122. package/src/runtime/thread/tool-cards.ts +383 -0
  123. package/src/runtime/turn-failure.ts +108 -0
  124. package/src/runtime/types.ts +148 -0
  125. package/src/runtime/usage-limit-error.ts +44 -0
  126. package/src/runtime/use-agent-activity.ts +80 -0
  127. package/src/runtime/use-conversation-stream.ts +1433 -0
  128. package/src/runtime/use-conversation-thread.ts +556 -0
  129. package/src/runtime/use-start-conversation.ts +107 -0
  130. package/src/runtime/use-thread-history.ts +64 -0
  131. package/src/runtime/use-thread-search.ts +95 -0
  132. package/src/runtime/use-turn-edit.ts +99 -0
  133. package/src/tools.ts +2 -2
  134. package/src/types.ts +18 -47
  135. package/src/components/AliaChatMessageList.tsx +0 -532
  136. package/src/components/ThinkingBlock.tsx +0 -43
  137. package/src/hooks/useAliaChat.ts +0 -573
  138. package/src/lib/catalogue.ts +0 -236
  139. package/src/lib/chat-stream.ts +0 -655
  140. package/src/lib/chat-transport.ts +0 -98
  141. package/src/lib/delegation.ts +0 -34
  142. package/src/lib/work-log-copy.ts +0 -61
@@ -1,98 +0,0 @@
1
- import type { MessageContent } from './content-utils';
2
- import {
3
- AliaChatStreamError,
4
- consumeAliaChatStream,
5
- readAliaChatFailure,
6
- type AliaChatStreamEvent,
7
- type AliaChatStreamResult,
8
- } from './chat-stream';
9
-
10
- export interface AuthenticatedResponseClient {
11
- requestAuthenticatedResponse(config: {
12
- method: 'POST';
13
- url: string;
14
- body: string;
15
- headers: Record<string, string>;
16
- signal: AbortSignal;
17
- }): Promise<Response>;
18
- }
19
-
20
- export interface AliaChatRequest {
21
- readonly url: string;
22
- /** `publisher/model`; omitted, the server's default model answers. */
23
- readonly model?: string;
24
- readonly messages: ReadonlyArray<{ readonly role: string; readonly content: MessageContent }>;
25
- /**
26
- * `'voice'` asks for an answer meant to be heard: short, conversational, no
27
- * formatting (the API layers its voice response profile over the turn's
28
- * prompt). Omitted for ordinary text chat, which sends exactly what it
29
- * always sent.
30
- */
31
- readonly responseMode?: 'voice';
32
- /** The agent whose thread this turn belongs to, when there is one. */
33
- readonly agentId?: string;
34
- }
35
-
36
- /**
37
- * The authenticated transport boundary for an SDK chat turn. Authentication,
38
- * preflight refresh and the single supported 401 replay belong to the linked
39
- * Oxy client; this layer never reads or writes bearer tokens itself.
40
- */
41
- export async function streamAliaChat(
42
- client: AuthenticatedResponseClient,
43
- request: AliaChatRequest,
44
- signal: AbortSignal,
45
- onEvent: (event: AliaChatStreamEvent) => void,
46
- ): Promise<AliaChatStreamResult> {
47
- const response = await client.requestAuthenticatedResponse({
48
- method: 'POST',
49
- url: request.url,
50
- headers: {
51
- Accept: 'text/event-stream',
52
- 'Content-Type': 'application/json',
53
- },
54
- body: JSON.stringify({
55
- ...(request.model === undefined ? {} : { model: request.model }),
56
- messages: request.messages,
57
- stream: true,
58
- ...(request.responseMode === undefined ? {} : { responseMode: request.responseMode }),
59
- ...(request.agentId === undefined ? {} : { agentId: request.agentId }),
60
- }),
61
- signal,
62
- });
63
-
64
- if (!response.ok) {
65
- throw new AliaChatStreamError(`Alia request failed with status ${response.status}.`, {
66
- ...(await readErrorEnvelope(response)),
67
- status: response.status,
68
- });
69
- }
70
-
71
- return consumeAliaChatStream(response, onEvent, signal);
72
- }
73
-
74
- /** Bodies larger than this are not an Alia error envelope and are not read. */
75
- const MAX_ERROR_BODY_BYTES = 16 * 1024;
76
-
77
- /**
78
- * The code, retryability and reference of an HTTP refusal or failed turn.
79
- *
80
- * Without them a caller cannot tell "send it again" (a 503 for a turn that
81
- * failed before any output) from "this will not work" (a 400), so the status
82
- * is not enough. A body that is large, not JSON or not the envelope yields
83
- * nothing, and the status alone still reaches the caller.
84
- */
85
- async function readErrorEnvelope(response: Response) {
86
- const length = Number(response.headers.get('content-length') ?? '0');
87
- if (Number.isFinite(length) && length > MAX_ERROR_BODY_BYTES) {
88
- await response.body?.cancel().catch(() => undefined);
89
- return {};
90
- }
91
- try {
92
- const text = await response.text();
93
- if (text.length > MAX_ERROR_BODY_BYTES) return {};
94
- return readAliaChatFailure(JSON.parse(text));
95
- } catch {
96
- return {};
97
- }
98
- }
@@ -1,34 +0,0 @@
1
- import type { ToolInvocation } from '../types';
2
-
3
- /** The tools that hand a question to another agent. */
4
- const DELEGATION_TOOLS = new Set(['delegateToAgent', 'askAgent']);
5
-
6
- export interface WorkingAgent {
7
- id: string;
8
- name: string;
9
- }
10
-
11
- const text = (value: unknown): string | undefined =>
12
- typeof value === 'string' && value.trim() !== '' ? value : undefined;
13
-
14
- /**
15
- * The agent a delegation call is for, from its arguments: an id (`agentId`) and a name
16
- * (`agentName`, or `agent` when it is a name). Whichever is missing falls back on the other, so
17
- * the placeholder and the answer that follows agree on who it is as long as the call names them.
18
- */
19
- export function delegatedAgent(invocation: ToolInvocation): WorkingAgent | null {
20
- if (!DELEGATION_TOOLS.has(invocation.toolName)) return null;
21
- const args = invocation.args ?? {};
22
- const id = text(args.agentId) ?? text(args.agent_id) ?? text(args.agent) ?? text(args.name);
23
- const name = text(args.agentName) ?? text(args.agent) ?? text(args.name) ?? id;
24
- if (!id || !name) return null;
25
- return { id, name };
26
- }
27
-
28
- /**
29
- * The id of an agent's message in a turn. A delegation call creates it empty (the agent is
30
- * thinking) and the agent's answer fills the same message, so one element carries the avatar from
31
- * thinking to answered.
32
- */
33
- export const agentMessageId = (assistantId: string, agentId: string) =>
34
- `${assistantId}-agent-${agentId}`;
@@ -1,61 +0,0 @@
1
- /**
2
- * The words of the work log (`work-log.ts`), keyed the way the Alia app's own catalogue keys
3
- * them, so the app hands its translator straight in. A host without one gets English.
4
- */
5
- export type Translate = (key: string, params?: Record<string, unknown>) => string;
6
-
7
- type Entry = string | { one: string; other: string };
8
-
9
- const CATALOGUE: Record<string, Entry> = {
10
- 'chat.bloom.researched': 'Researched',
11
- 'chat.bloom.searchCount': { one: '1 search', other: '{{count}} searches' },
12
- 'chat.bloom.searchedWeb': 'Searched the web for',
13
- 'chat.bloom.searchFailed': 'Search failed',
14
- 'chat.bloom.noResults': 'No results',
15
- 'chat.bloom.resultCount': { one: '1 result', other: '{{count}} results' },
16
- 'chat.bloom.visited': 'Visited',
17
- 'chat.bloom.researching': 'Researching',
18
- 'chat.bloom.sourceCount': { one: '1 source', other: '{{count}} sources' },
19
- 'chat.bloom.createdFile': 'Created',
20
- 'chat.bloom.writingFile': 'Writing',
21
- 'chat.bloom.taskInput': 'With',
22
- 'chat.bloom.taskFailed': 'Returned an error',
23
- 'chat.bloom.taskStopped': "Didn't finish",
24
- 'tasks.tool.pill.browse': 'Browsing',
25
- 'tasks.tool.pill.webSearch': 'Web search',
26
- 'tasks.tool.pill.webScraper': 'Reading page',
27
- 'tasks.tool.pill.generateFile': 'Generating file',
28
- 'tasks.tool.pill.sendTelegramMessage': 'Telegram',
29
- 'tasks.tool.pill.sendSlack': 'Slack',
30
- 'tasks.tool.pill.sendDiscord': 'Discord',
31
- 'tasks.tool.pill.sendSignal': 'Signal',
32
- 'tasks.tool.pill.sendEmail': 'Email',
33
- 'tasks.tool.pill.delegateToAgent': 'Delegating',
34
- 'tasks.tool.pill.askAgent': 'Asking an agent',
35
- 'tasks.tool.pill.useApps': 'Opening apps',
36
- 'tasks.tool.pill.agentSearch': 'Searching agents',
37
- 'tasks.tool.pill.userMemory': 'Remembering',
38
- 'tasks.tool.pill.shellExec': 'Running command',
39
- 'tasks.tool.pill.fileEdit': 'Editing file',
40
- 'tasks.tool.pill.codeInterpreter': 'Running code',
41
- 'tasks.tool.done.browse': 'Browsed',
42
- 'tasks.tool.done.webScraper': 'Read page',
43
- 'tasks.tool.done.generateFile': 'Generated file',
44
- 'tasks.tool.done.delegateToAgent': 'Delegated',
45
- 'tasks.tool.done.askAgent': 'Asked an agent',
46
- 'tasks.tool.done.useApps': 'Opened apps',
47
- 'tasks.tool.done.agentSearch': 'Searched agents',
48
- 'tasks.tool.done.userMemory': 'Remembered',
49
- 'tasks.tool.done.shellExec': 'Ran command',
50
- 'tasks.tool.done.fileEdit': 'Edited file',
51
- 'tasks.tool.done.codeInterpreter': 'Ran code',
52
- };
53
-
54
- /** The default translator: the English above, with `{{count}}` plurals. */
55
- export const englishWorkLog: Translate = (key, params) => {
56
- const entry = CATALOGUE[key];
57
- if (entry === undefined) return key;
58
- const count = typeof params?.count === 'number' ? params.count : undefined;
59
- const text = typeof entry === 'string' ? entry : count === 1 ? entry.one : entry.other;
60
- return text.replace('{{count}}', String(count ?? ''));
61
- };