@salmonui/chat 0.0.0-stage → 0.2.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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/conversation/Conversation.d.ts +4 -0
  4. package/dist/conversation/Conversation.d.ts.map +1 -0
  5. package/dist/conversation/Conversation.js +588 -0
  6. package/dist/conversation/Conversation.js.map +1 -0
  7. package/dist/conversation/Item.d.ts +67 -0
  8. package/dist/conversation/Item.d.ts.map +1 -0
  9. package/dist/conversation/Item.js +149 -0
  10. package/dist/conversation/Item.js.map +1 -0
  11. package/dist/conversation/assistant-lazy.d.ts +6 -0
  12. package/dist/conversation/assistant-lazy.d.ts.map +1 -0
  13. package/dist/conversation/assistant-lazy.js +16 -0
  14. package/dist/conversation/assistant-lazy.js.map +1 -0
  15. package/dist/conversation/assistant-static.d.ts +4 -0
  16. package/dist/conversation/assistant-static.d.ts.map +1 -0
  17. package/dist/conversation/assistant-static.js +9 -0
  18. package/dist/conversation/assistant-static.js.map +1 -0
  19. package/dist/conversation/assistant-types.d.ts +2 -0
  20. package/dist/conversation/assistant-types.d.ts.map +1 -0
  21. package/dist/conversation/assistant-types.js +3 -0
  22. package/dist/conversation/assistant-types.js.map +1 -0
  23. package/dist/conversation/assistant.d.ts +54 -0
  24. package/dist/conversation/assistant.d.ts.map +1 -0
  25. package/dist/conversation/assistant.js +348 -0
  26. package/dist/conversation/assistant.js.map +1 -0
  27. package/dist/conversation/context.d.ts +80 -0
  28. package/dist/conversation/context.d.ts.map +1 -0
  29. package/dist/conversation/context.js +40 -0
  30. package/dist/conversation/context.js.map +1 -0
  31. package/dist/conversation/format.d.ts +33 -0
  32. package/dist/conversation/format.d.ts.map +1 -0
  33. package/dist/conversation/format.js +150 -0
  34. package/dist/conversation/format.js.map +1 -0
  35. package/dist/conversation/parts.d.ts +16 -0
  36. package/dist/conversation/parts.d.ts.map +1 -0
  37. package/dist/conversation/parts.js +326 -0
  38. package/dist/conversation/parts.js.map +1 -0
  39. package/dist/conversation/runner.d.ts +15 -0
  40. package/dist/conversation/runner.d.ts.map +1 -0
  41. package/dist/conversation/runner.js +52 -0
  42. package/dist/conversation/runner.js.map +1 -0
  43. package/dist/conversation/store.d.ts +63 -0
  44. package/dist/conversation/store.d.ts.map +1 -0
  45. package/dist/conversation/store.js +142 -0
  46. package/dist/conversation/store.js.map +1 -0
  47. package/dist/conversation/types.d.ts +473 -0
  48. package/dist/conversation/types.d.ts.map +1 -0
  49. package/dist/conversation/types.js +5 -0
  50. package/dist/conversation/types.js.map +1 -0
  51. package/dist/conversation.css +788 -0
  52. package/dist/conversation.d.ts +18 -0
  53. package/dist/conversation.d.ts.map +1 -0
  54. package/dist/conversation.js +26 -0
  55. package/dist/conversation.js.map +1 -0
  56. package/dist/inline-assist/InlineAssist.d.ts +16 -0
  57. package/dist/inline-assist/InlineAssist.d.ts.map +1 -0
  58. package/dist/inline-assist/InlineAssist.js +384 -0
  59. package/dist/inline-assist/InlineAssist.js.map +1 -0
  60. package/dist/inline-assist/model.d.ts +40 -0
  61. package/dist/inline-assist/model.d.ts.map +1 -0
  62. package/dist/inline-assist/model.js +87 -0
  63. package/dist/inline-assist/model.js.map +1 -0
  64. package/dist/inline-assist/types.d.ts +216 -0
  65. package/dist/inline-assist/types.d.ts.map +1 -0
  66. package/dist/inline-assist/types.js +5 -0
  67. package/dist/inline-assist/types.js.map +1 -0
  68. package/dist/inline-assist.css +890 -0
  69. package/dist/inline-assist.d.ts +5 -0
  70. package/dist/inline-assist.d.ts.map +1 -0
  71. package/dist/inline-assist.js +12 -0
  72. package/dist/inline-assist.js.map +1 -0
  73. package/dist/internal/stream-run.d.ts +71 -0
  74. package/dist/internal/stream-run.d.ts.map +1 -0
  75. package/dist/internal/stream-run.js +161 -0
  76. package/dist/internal/stream-run.js.map +1 -0
  77. package/dist/internal/suggest.d.ts +90 -0
  78. package/dist/internal/suggest.d.ts.map +1 -0
  79. package/dist/internal/suggest.js +332 -0
  80. package/dist/internal/suggest.js.map +1 -0
  81. package/dist/smart-paste/fields.d.ts +31 -0
  82. package/dist/smart-paste/fields.d.ts.map +1 -0
  83. package/dist/smart-paste/fields.js +162 -0
  84. package/dist/smart-paste/fields.js.map +1 -0
  85. package/dist/smart-paste/useSmartPaste.d.ts +38 -0
  86. package/dist/smart-paste/useSmartPaste.d.ts.map +1 -0
  87. package/dist/smart-paste/useSmartPaste.js +56 -0
  88. package/dist/smart-paste/useSmartPaste.js.map +1 -0
  89. package/dist/smart-paste.d.ts +3 -0
  90. package/dist/smart-paste.d.ts.map +1 -0
  91. package/dist/smart-paste.js +6 -0
  92. package/dist/smart-paste.js.map +1 -0
  93. package/dist/styles.css +1754 -0
  94. package/dist/text-suggest/useTextSuggest.d.ts +13 -0
  95. package/dist/text-suggest/useTextSuggest.d.ts.map +1 -0
  96. package/dist/text-suggest/useTextSuggest.js +55 -0
  97. package/dist/text-suggest/useTextSuggest.js.map +1 -0
  98. package/dist/text-suggest.css +78 -0
  99. package/dist/text-suggest.d.ts +4 -0
  100. package/dist/text-suggest.d.ts.map +1 -0
  101. package/dist/text-suggest.js +9 -0
  102. package/dist/text-suggest.js.map +1 -0
  103. package/package.json +68 -4
@@ -0,0 +1,13 @@
1
+ import { type SuggestOptions } from '../internal/suggest.js';
2
+ export type TextSuggestOptions = SuggestOptions;
3
+ export interface TextSuggest {
4
+ /** Pass to the field: `<TextArea ref={suggest.ref} />` (a stable callback ref). */
5
+ readonly ref: (textarea: HTMLTextAreaElement | null) => void;
6
+ }
7
+ /**
8
+ * Attaches inline suggestions to the `<textarea>` that receives `ref`. Options
9
+ * are read when events happen, so `suggest` and the callbacks may be inline
10
+ * functions.
11
+ */
12
+ export declare function useTextSuggest(options: TextSuggestOptions): TextSuggest;
13
+ //# sourceMappingURL=useTextSuggest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTextSuggest.d.ts","sourceRoot":"","sources":["../../src/text-suggest/useTextSuggest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEpG,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC1B,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,CAAC;CAC9D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAkCvE"}
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ // `useTextSuggest`:
3
+ // inline completions for any native <textarea>, the Inputs `TextArea` first.
4
+ // An explicit composition: the application calls the hook and passes `ref`
5
+ // to the field, so `@salmonui/inputs/text-field` carries no suggestion code
6
+ // and no loader. The controller
7
+ // (`internal/suggest.ts`) owns the ghost text, the hint and the polite live
8
+ // region as DOM next to the field; nothing here touches React state, and the
9
+ // server render is unchanged (the ref never runs there).
10
+ import { useCallback, useLayoutEffect, useRef } from 'react';
11
+ import { useLocaleText } from '@salmonui/core/internal/locale';
12
+ import { attachSuggest } from '../internal/suggest.js';
13
+ /**
14
+ * Attaches inline suggestions to the `<textarea>` that receives `ref`. Options
15
+ * are read when events happen, so `suggest` and the callbacks may be inline
16
+ * functions.
17
+ */
18
+ export function useTextSuggest(options) {
19
+ const latest = useRef(options);
20
+ // The attached field and its controller. A ref forwarded through a
21
+ // component that builds a new callback per render (the Inputs `TextArea`)
22
+ // is called with `null` and then the same element on every commit, so a
23
+ // detach waits for a microtask and is cancelled when the element comes
24
+ // back: the controller (and a request in flight) survives re-renders.
25
+ const attached = useRef(null);
26
+ const localeText = useLocaleText('textSuggest', options.localeText);
27
+ useLayoutEffect(() => {
28
+ // The controller reads `localeText`: the provider-merged text.
29
+ attached.current?.controller.update((latest.current = { ...options, localeText }));
30
+ });
31
+ const ref = useCallback((textarea) => {
32
+ const current = attached.current;
33
+ if (current && current.el === textarea) {
34
+ current.leaving = false;
35
+ return undefined;
36
+ }
37
+ if (!textarea) {
38
+ if (!current)
39
+ return undefined;
40
+ current.leaving = true;
41
+ queueMicrotask(() => {
42
+ if (!current.leaving || attached.current !== current)
43
+ return;
44
+ current.controller.dispose();
45
+ attached.current = null;
46
+ });
47
+ return undefined;
48
+ }
49
+ current?.controller.dispose();
50
+ attached.current = { el: textarea, controller: attachSuggest(textarea, latest.current), leaving: false };
51
+ return undefined;
52
+ }, []);
53
+ return { ref };
54
+ }
55
+ //# sourceMappingURL=useTextSuggest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTextSuggest.js","sourceRoot":"","sources":["../../src/text-suggest/useTextSuggest.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,oBAAoB;AACpB,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,gCAAgC;AAChC,4EAA4E;AAC5E,6EAA6E;AAC7E,yDAAyD;AAEzD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAA+C,MAAM,wBAAwB,CAAC;AASpG;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAA2B;IACxD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,mEAAmE;IACnE,0EAA0E;IAC1E,wEAAwE;IACxE,uEAAuE;IACvE,sEAAsE;IACtE,MAAM,QAAQ,GAAG,MAAM,CAAsF,IAAI,CAAC,CAAC;IACnH,MAAM,UAAU,GAAG,aAAa,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpE,eAAe,CAAC,GAAG,EAAE;QACnB,+DAA+D;QAC/D,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,QAAoC,EAAE,EAAE;QAC/D,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,IAAI,OAAO,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YACvC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAC;YAC/B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;YACvB,cAAc,CAAC,GAAG,EAAE;gBAClB,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;oBAAE,OAAO;gBAC7D,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBAC7B,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;YAC1B,CAAC,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;QAC9B,QAAQ,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACzG,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC"}
@@ -0,0 +1,78 @@
1
+ @layer salmon.a;
2
+ @layer salmon.a {
3
+ /* @salmonui/react/text-suggest: the overlay, hint and live region useTextSuggest adds next
4
+ to the textarea. The controller writes the suggestion into `.salmon-text-suggest` at
5
+ the caret (top/left, `--salmon-text-suggest-line` = one line,
6
+ `--salmon-text-suggest-room` = space to the content edge). `auto` is inline
7
+ ghost text on fine pointers and a popover on coarse pointers, decided here
8
+ by media query. */
9
+ .salmon-text-suggest {
10
+ position: absolute;
11
+ z-index: 1;
12
+ box-sizing: border-box;
13
+ max-inline-size: var(--salmon-text-suggest-room);
14
+ overflow: hidden;
15
+ color: var(--salmon-text-placeholder);
16
+ white-space: pre;
17
+ text-overflow: ellipsis;
18
+ pointer-events: none;
19
+ user-select: none;
20
+ }
21
+
22
+ .salmon-text-suggest[hidden] {
23
+ display: none;
24
+ }
25
+
26
+ /* Right-to-left: anchored at the caret's right edge, the text runs leftwards. */
27
+ .salmon-text-suggest[data-rtl] {
28
+ translate: -100% 0;
29
+ }
30
+
31
+ .salmon-text-suggest[data-suggestion-display='popover'] {
32
+ max-inline-size: min(360px, calc(100vw - 16px));
33
+ margin-block-start: var(--salmon-text-suggest-line);
34
+ padding: 4px 8px;
35
+ color: var(--salmon-text-secondary);
36
+ white-space: pre-wrap;
37
+ background: var(--salmon-surface-overlay);
38
+ border: 1px solid var(--salmon-border-default);
39
+ border-radius: var(--salmon-radius-md);
40
+ box-shadow: var(--salmon-shadow-md);
41
+ pointer-events: auto;
42
+ cursor: pointer;
43
+ }
44
+
45
+ @media (pointer: coarse) {
46
+ .salmon-text-suggest[data-suggestion-display='auto'] {
47
+ max-inline-size: min(360px, calc(100vw - 16px));
48
+ margin-block-start: var(--salmon-text-suggest-line);
49
+ padding: 4px 8px;
50
+ color: var(--salmon-text-secondary);
51
+ white-space: pre-wrap;
52
+ background: var(--salmon-surface-overlay);
53
+ border: 1px solid var(--salmon-border-default);
54
+ border-radius: var(--salmon-radius-md);
55
+ box-shadow: var(--salmon-shadow-md);
56
+ pointer-events: auto;
57
+ cursor: pointer;
58
+ }
59
+ }
60
+
61
+ /* The hint and the live region are in the accessibility tree only. */
62
+ .salmon-text-suggest-hint,
63
+ .salmon-text-suggest-live {
64
+ position: absolute;
65
+ inline-size: 1px;
66
+ block-size: 1px;
67
+ overflow: hidden;
68
+ clip-path: inset(50%);
69
+ white-space: nowrap;
70
+ }
71
+
72
+ @media (forced-colors: active) {
73
+ .salmon-text-suggest {
74
+ color: GrayText;
75
+ }
76
+ }
77
+
78
+ }
@@ -0,0 +1,4 @@
1
+ export { useTextSuggest } from './text-suggest/useTextSuggest.js';
2
+ export type { TextSuggest, TextSuggestOptions } from './text-suggest/useTextSuggest.js';
3
+ export type { BeforeSuggestionShowEvent, SuggestContext, SuggestFunction, SuggestionDisplay, SuggestionEvent, SuggestLocaleText } from './internal/suggest.js';
4
+ //# sourceMappingURL=text-suggest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-suggest.d.ts","sourceRoot":"","sources":["../src/text-suggest.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACxF,YAAY,EAAE,yBAAyB,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ import { expectStylesheet } from '@salmonui/core/internal/dev';
3
+ // `@salmonui/chat/text-suggest`: `useTextSuggest`,
4
+ // inline completions wired to the Inputs `TextArea` (or any native
5
+ // <textarea>) through its `ref`. CSS: `@salmonui/chat/text-suggest/styles.css`.
6
+ export { useTextSuggest } from './text-suggest/useTextSuggest.js';
7
+ if (process.env.NODE_ENV !== 'production')
8
+ expectStylesheet('@salmonui/chat/text-suggest', 'salmon-text-suggest');
9
+ //# sourceMappingURL=text-suggest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-suggest.js","sourceRoot":"","sources":["../src/text-suggest.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,mDAAmD;AACnD,mEAAmE;AACnE,gFAAgF;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAOlE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,gBAAgB,CAAC,6BAA6B,EAAE,qBAAqB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@salmonui/chat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Conversation, InlineAssist, TextSuggest and SmartPaste for Salmon UI with provider-agnostic AI adapters.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/hy-ong/salmonui.git",
9
+ "directory": "packages/chat"
10
+ },
11
+ "homepage": "https://salmonui.dev",
12
+ "bugs": {
13
+ "url": "https://github.com/hy-ong/salmonui/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": [
17
+ "**/*.css"
18
+ ],
19
+ "exports": {
20
+ "./conversation": {
21
+ "types": "./dist/conversation.d.ts",
22
+ "import": "./dist/conversation.js"
23
+ },
24
+ "./inline-assist": {
25
+ "types": "./dist/inline-assist.d.ts",
26
+ "import": "./dist/inline-assist.js"
27
+ },
28
+ "./text-suggest": {
29
+ "types": "./dist/text-suggest.d.ts",
30
+ "import": "./dist/text-suggest.js"
31
+ },
32
+ "./smart-paste": {
33
+ "types": "./dist/smart-paste.d.ts",
34
+ "import": "./dist/smart-paste.js"
35
+ },
36
+ "./conversation/styles.css": "./dist/conversation.css",
37
+ "./inline-assist/styles.css": "./dist/inline-assist.css",
38
+ "./text-suggest/styles.css": "./dist/text-suggest.css",
39
+ "./styles.css": "./dist/styles.css",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "imports": {
43
+ "#conversation-assistant": {
44
+ "types": "./dist/conversation/assistant-static.d.ts",
45
+ "workerd": "./dist/conversation/assistant-static.js",
46
+ "worker": "./dist/conversation/assistant-static.js",
47
+ "edge-light": "./dist/conversation/assistant-static.js",
48
+ "browser": "./dist/conversation/assistant-lazy.js",
49
+ "default": "./dist/conversation/assistant-static.js"
50
+ }
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "README.md",
55
+ "LICENSE"
56
+ ],
57
+ "dependencies": {
58
+ "@salmonui/core": "0.2.0",
59
+ "@salmonui/buttons": "0.2.0",
60
+ "@salmonui/dropdowns": "0.2.0",
61
+ "@salmonui/inputs": "0.2.0"
62
+ },
63
+ "peerDependencies": {
64
+ "react": ">=19",
65
+ "react-dom": ">=19"
66
+ },
67
+ "engines": {
68
+ "node": ">=22"
69
+ }
70
+ }