@nucleux/agent-composer 0.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.
- package/LICENSE +21 -0
- package/dist/index.cjs +121 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var utils = require('@nucleux/utils');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
+
|
|
29
|
+
// src/index.tsx
|
|
30
|
+
var AgentComposer = React__namespace.forwardRef(
|
|
31
|
+
({
|
|
32
|
+
value,
|
|
33
|
+
onValueChange,
|
|
34
|
+
onSubmit,
|
|
35
|
+
placeholder = "Describe a task, workflow or goal\u2026",
|
|
36
|
+
leftActions,
|
|
37
|
+
rightActions,
|
|
38
|
+
loading = false,
|
|
39
|
+
onStop,
|
|
40
|
+
maxHeight = 200,
|
|
41
|
+
disabled,
|
|
42
|
+
className,
|
|
43
|
+
...props
|
|
44
|
+
}, forwardedRef) => {
|
|
45
|
+
const innerRef = React__namespace.useRef(null);
|
|
46
|
+
React__namespace.useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
47
|
+
React__namespace.useLayoutEffect(() => {
|
|
48
|
+
const el = innerRef.current;
|
|
49
|
+
if (!el) return;
|
|
50
|
+
el.style.height = "auto";
|
|
51
|
+
el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;
|
|
52
|
+
}, [value, maxHeight]);
|
|
53
|
+
const canSend = value.trim().length > 0 && !disabled;
|
|
54
|
+
const submit = () => {
|
|
55
|
+
if (canSend) onSubmit(value.trim());
|
|
56
|
+
};
|
|
57
|
+
const handleKeyDown = (e) => {
|
|
58
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
submit();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
className: utils.cn(
|
|
67
|
+
"flex flex-col gap-3 rounded-xl border border-input bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring",
|
|
68
|
+
className
|
|
69
|
+
),
|
|
70
|
+
...props,
|
|
71
|
+
children: [
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
73
|
+
"textarea",
|
|
74
|
+
{
|
|
75
|
+
ref: innerRef,
|
|
76
|
+
rows: 1,
|
|
77
|
+
value,
|
|
78
|
+
disabled,
|
|
79
|
+
placeholder,
|
|
80
|
+
"aria-label": typeof placeholder === "string" ? placeholder : "Message",
|
|
81
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
82
|
+
onKeyDown: handleKeyDown,
|
|
83
|
+
className: "max-h-[inherit] w-full resize-none bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50"
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1", children: leftActions }),
|
|
88
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
89
|
+
rightActions,
|
|
90
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
"button",
|
|
92
|
+
{
|
|
93
|
+
type: "button",
|
|
94
|
+
onClick: onStop,
|
|
95
|
+
"aria-label": "Stop generating",
|
|
96
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
97
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Square, { className: "size-3.5 fill-current" })
|
|
98
|
+
}
|
|
99
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
100
|
+
"button",
|
|
101
|
+
{
|
|
102
|
+
type: "button",
|
|
103
|
+
onClick: submit,
|
|
104
|
+
disabled: !canSend,
|
|
105
|
+
"aria-label": "Send",
|
|
106
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40",
|
|
107
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "size-4" })
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] })
|
|
111
|
+
] })
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
AgentComposer.displayName = "AgentComposer";
|
|
118
|
+
|
|
119
|
+
exports.AgentComposer = AgentComposer;
|
|
120
|
+
//# sourceMappingURL=index.cjs.map
|
|
121
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsxs","cn","jsx","Square","ArrowUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BO,IAAM,aAAA,GAAsBA,gBAAA,CAAA,UAAA;AAAA,EACjC,CACE;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA,GAAc,yCAAA;AAAA,IACd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AAA,CAACE,mBAAA,EAAA,EAAQ,SAAA,EAAU,QAAA,EAAS;AAAA;AAAA;AAC9B,aAAA,EAEJ;AAAA,WAAA,EACF;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,aAAA,CAAc,WAAA,GAAc,eAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { ArrowUp, Square } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface AgentComposerProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSubmit\"> {\n /** Controlled textarea value. */\n value: string;\n onValueChange: (value: string) => void;\n /** Called with the trimmed value on submit (Enter or send). */\n onSubmit: (value: string) => void;\n placeholder?: string;\n /** Toolbar content on the left (e.g. attach button). */\n leftActions?: React.ReactNode;\n /** Toolbar content on the right of the input, before the send button (e.g. model picker, mic). */\n rightActions?: React.ReactNode;\n /** Show the agent as busy — swaps send for a stop button. */\n loading?: boolean;\n onStop?: () => void;\n /** Max auto-grow height in px. */\n maxHeight?: number;\n /** Disable input + send. */\n disabled?: boolean;\n}\n\n/**\n * An agent task composer — a card with an auto-growing prompt field and a\n * toolbar (left actions, right actions, and a send/stop button). Enter submits,\n * Shift+Enter inserts a newline. Source: Figma \"Agentic\".\n */\nexport const AgentComposer = React.forwardRef<HTMLTextAreaElement, AgentComposerProps>(\n (\n {\n value,\n onValueChange,\n onSubmit,\n placeholder = \"Describe a task, workflow or goal…\",\n leftActions,\n rightActions,\n loading = false,\n onStop,\n maxHeight = 200,\n disabled,\n className,\n ...props\n },\n forwardedRef,\n ) => {\n const innerRef = React.useRef<HTMLTextAreaElement>(null);\n React.useImperativeHandle(forwardedRef, () => innerRef.current as HTMLTextAreaElement);\n\n React.useLayoutEffect(() => {\n const el = innerRef.current;\n if (!el) return;\n el.style.height = \"auto\";\n el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;\n }, [value, maxHeight]);\n\n const canSend = value.trim().length > 0 && !disabled;\n const submit = () => {\n if (canSend) onSubmit(value.trim());\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n e.preventDefault();\n submit();\n }\n };\n\n return (\n <div\n className={cn(\n \"flex flex-col gap-3 rounded-xl border border-input bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring\",\n className,\n )}\n {...props}\n >\n <textarea\n ref={innerRef}\n rows={1}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n aria-label={typeof placeholder === \"string\" ? placeholder : \"Message\"}\n onChange={(e) => onValueChange(e.target.value)}\n onKeyDown={handleKeyDown}\n className=\"max-h-[inherit] w-full resize-none bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50\"\n />\n <div className=\"flex items-center justify-between gap-2\">\n <div className=\"flex items-center gap-1\">{leftActions}</div>\n <div className=\"flex items-center gap-2\">\n {rightActions}\n {loading ? (\n <button\n type=\"button\"\n onClick={onStop}\n aria-label=\"Stop generating\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Square className=\"size-3.5 fill-current\" />\n </button>\n ) : (\n <button\n type=\"button\"\n onClick={submit}\n disabled={!canSend}\n aria-label=\"Send\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n <ArrowUp className=\"size-4\" />\n </button>\n )}\n </div>\n </div>\n </div>\n );\n },\n);\nAgentComposer.displayName = \"AgentComposer\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface AgentComposerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
|
|
4
|
+
/** Controlled textarea value. */
|
|
5
|
+
value: string;
|
|
6
|
+
onValueChange: (value: string) => void;
|
|
7
|
+
/** Called with the trimmed value on submit (Enter or send). */
|
|
8
|
+
onSubmit: (value: string) => void;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Toolbar content on the left (e.g. attach button). */
|
|
11
|
+
leftActions?: React.ReactNode;
|
|
12
|
+
/** Toolbar content on the right of the input, before the send button (e.g. model picker, mic). */
|
|
13
|
+
rightActions?: React.ReactNode;
|
|
14
|
+
/** Show the agent as busy — swaps send for a stop button. */
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
onStop?: () => void;
|
|
17
|
+
/** Max auto-grow height in px. */
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
/** Disable input + send. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An agent task composer — a card with an auto-growing prompt field and a
|
|
24
|
+
* toolbar (left actions, right actions, and a send/stop button). Enter submits,
|
|
25
|
+
* Shift+Enter inserts a newline. Source: Figma "Agentic".
|
|
26
|
+
*/
|
|
27
|
+
declare const AgentComposer: React.ForwardRefExoticComponent<AgentComposerProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
28
|
+
|
|
29
|
+
export { AgentComposer, type AgentComposerProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface AgentComposerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
|
|
4
|
+
/** Controlled textarea value. */
|
|
5
|
+
value: string;
|
|
6
|
+
onValueChange: (value: string) => void;
|
|
7
|
+
/** Called with the trimmed value on submit (Enter or send). */
|
|
8
|
+
onSubmit: (value: string) => void;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Toolbar content on the left (e.g. attach button). */
|
|
11
|
+
leftActions?: React.ReactNode;
|
|
12
|
+
/** Toolbar content on the right of the input, before the send button (e.g. model picker, mic). */
|
|
13
|
+
rightActions?: React.ReactNode;
|
|
14
|
+
/** Show the agent as busy — swaps send for a stop button. */
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
onStop?: () => void;
|
|
17
|
+
/** Max auto-grow height in px. */
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
/** Disable input + send. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An agent task composer — a card with an auto-growing prompt field and a
|
|
24
|
+
* toolbar (left actions, right actions, and a send/stop button). Enter submits,
|
|
25
|
+
* Shift+Enter inserts a newline. Source: Figma "Agentic".
|
|
26
|
+
*/
|
|
27
|
+
declare const AgentComposer: React.ForwardRefExoticComponent<AgentComposerProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
28
|
+
|
|
29
|
+
export { AgentComposer, type AgentComposerProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Square, ArrowUp } from 'lucide-react';
|
|
4
|
+
import { cn } from '@nucleux/utils';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/index.tsx
|
|
8
|
+
var AgentComposer = React.forwardRef(
|
|
9
|
+
({
|
|
10
|
+
value,
|
|
11
|
+
onValueChange,
|
|
12
|
+
onSubmit,
|
|
13
|
+
placeholder = "Describe a task, workflow or goal\u2026",
|
|
14
|
+
leftActions,
|
|
15
|
+
rightActions,
|
|
16
|
+
loading = false,
|
|
17
|
+
onStop,
|
|
18
|
+
maxHeight = 200,
|
|
19
|
+
disabled,
|
|
20
|
+
className,
|
|
21
|
+
...props
|
|
22
|
+
}, forwardedRef) => {
|
|
23
|
+
const innerRef = React.useRef(null);
|
|
24
|
+
React.useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
25
|
+
React.useLayoutEffect(() => {
|
|
26
|
+
const el = innerRef.current;
|
|
27
|
+
if (!el) return;
|
|
28
|
+
el.style.height = "auto";
|
|
29
|
+
el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;
|
|
30
|
+
}, [value, maxHeight]);
|
|
31
|
+
const canSend = value.trim().length > 0 && !disabled;
|
|
32
|
+
const submit = () => {
|
|
33
|
+
if (canSend) onSubmit(value.trim());
|
|
34
|
+
};
|
|
35
|
+
const handleKeyDown = (e) => {
|
|
36
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
submit();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return /* @__PURE__ */ jsxs(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
className: cn(
|
|
45
|
+
"flex flex-col gap-3 rounded-xl border border-input bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring",
|
|
46
|
+
className
|
|
47
|
+
),
|
|
48
|
+
...props,
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ jsx(
|
|
51
|
+
"textarea",
|
|
52
|
+
{
|
|
53
|
+
ref: innerRef,
|
|
54
|
+
rows: 1,
|
|
55
|
+
value,
|
|
56
|
+
disabled,
|
|
57
|
+
placeholder,
|
|
58
|
+
"aria-label": typeof placeholder === "string" ? placeholder : "Message",
|
|
59
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
60
|
+
onKeyDown: handleKeyDown,
|
|
61
|
+
className: "max-h-[inherit] w-full resize-none bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50"
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
65
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: leftActions }),
|
|
66
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
67
|
+
rightActions,
|
|
68
|
+
loading ? /* @__PURE__ */ jsx(
|
|
69
|
+
"button",
|
|
70
|
+
{
|
|
71
|
+
type: "button",
|
|
72
|
+
onClick: onStop,
|
|
73
|
+
"aria-label": "Stop generating",
|
|
74
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
75
|
+
children: /* @__PURE__ */ jsx(Square, { className: "size-3.5 fill-current" })
|
|
76
|
+
}
|
|
77
|
+
) : /* @__PURE__ */ jsx(
|
|
78
|
+
"button",
|
|
79
|
+
{
|
|
80
|
+
type: "button",
|
|
81
|
+
onClick: submit,
|
|
82
|
+
disabled: !canSend,
|
|
83
|
+
"aria-label": "Send",
|
|
84
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40",
|
|
85
|
+
children: /* @__PURE__ */ jsx(ArrowUp, { className: "size-4" })
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
] })
|
|
89
|
+
] })
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
AgentComposer.displayName = "AgentComposer";
|
|
96
|
+
|
|
97
|
+
export { AgentComposer };
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AA8BO,IAAM,aAAA,GAAsB,KAAA,CAAA,UAAA;AAAA,EACjC,CACE;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA,GAAc,yCAAA;AAAA,IACd,WAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,MAA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AAAA,WAAA,EACF;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,aAAA,CAAc,WAAA,GAAc,eAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { ArrowUp, Square } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface AgentComposerProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSubmit\"> {\n /** Controlled textarea value. */\n value: string;\n onValueChange: (value: string) => void;\n /** Called with the trimmed value on submit (Enter or send). */\n onSubmit: (value: string) => void;\n placeholder?: string;\n /** Toolbar content on the left (e.g. attach button). */\n leftActions?: React.ReactNode;\n /** Toolbar content on the right of the input, before the send button (e.g. model picker, mic). */\n rightActions?: React.ReactNode;\n /** Show the agent as busy — swaps send for a stop button. */\n loading?: boolean;\n onStop?: () => void;\n /** Max auto-grow height in px. */\n maxHeight?: number;\n /** Disable input + send. */\n disabled?: boolean;\n}\n\n/**\n * An agent task composer — a card with an auto-growing prompt field and a\n * toolbar (left actions, right actions, and a send/stop button). Enter submits,\n * Shift+Enter inserts a newline. Source: Figma \"Agentic\".\n */\nexport const AgentComposer = React.forwardRef<HTMLTextAreaElement, AgentComposerProps>(\n (\n {\n value,\n onValueChange,\n onSubmit,\n placeholder = \"Describe a task, workflow or goal…\",\n leftActions,\n rightActions,\n loading = false,\n onStop,\n maxHeight = 200,\n disabled,\n className,\n ...props\n },\n forwardedRef,\n ) => {\n const innerRef = React.useRef<HTMLTextAreaElement>(null);\n React.useImperativeHandle(forwardedRef, () => innerRef.current as HTMLTextAreaElement);\n\n React.useLayoutEffect(() => {\n const el = innerRef.current;\n if (!el) return;\n el.style.height = \"auto\";\n el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;\n }, [value, maxHeight]);\n\n const canSend = value.trim().length > 0 && !disabled;\n const submit = () => {\n if (canSend) onSubmit(value.trim());\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n e.preventDefault();\n submit();\n }\n };\n\n return (\n <div\n className={cn(\n \"flex flex-col gap-3 rounded-xl border border-input bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring\",\n className,\n )}\n {...props}\n >\n <textarea\n ref={innerRef}\n rows={1}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n aria-label={typeof placeholder === \"string\" ? placeholder : \"Message\"}\n onChange={(e) => onValueChange(e.target.value)}\n onKeyDown={handleKeyDown}\n className=\"max-h-[inherit] w-full resize-none bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50\"\n />\n <div className=\"flex items-center justify-between gap-2\">\n <div className=\"flex items-center gap-1\">{leftActions}</div>\n <div className=\"flex items-center gap-2\">\n {rightActions}\n {loading ? (\n <button\n type=\"button\"\n onClick={onStop}\n aria-label=\"Stop generating\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Square className=\"size-3.5 fill-current\" />\n </button>\n ) : (\n <button\n type=\"button\"\n onClick={submit}\n disabled={!canSend}\n aria-label=\"Send\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n <ArrowUp className=\"size-4\" />\n </button>\n )}\n </div>\n </div>\n </div>\n );\n },\n);\nAgentComposer.displayName = \"AgentComposer\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/agent-composer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18",
|
|
21
|
+
"react-dom": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"lucide-react": "^0.469.0",
|
|
25
|
+
"@nucleux/utils": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2",
|
|
30
|
+
"@types/react": "^18.3.18",
|
|
31
|
+
"react": "^18.3.1"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
40
|
+
"directory": "packages/agent-composer"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup"
|
|
45
|
+
}
|
|
46
|
+
}
|