@agentskit/ink 0.4.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emerson Braun
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,131 @@
1
+ 'use strict';
2
+
3
+ var core = require('@agentskit/core');
4
+ var react = require('react');
5
+ var ink = require('ink');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ // src/index.ts
9
+ function useChat(config) {
10
+ const controllerRef = react.useRef(null);
11
+ if (!controllerRef.current) {
12
+ controllerRef.current = core.createChatController(config);
13
+ }
14
+ react.useEffect(() => {
15
+ controllerRef.current?.updateConfig(config);
16
+ }, [config]);
17
+ const state = react.useSyncExternalStore(
18
+ controllerRef.current.subscribe,
19
+ controllerRef.current.getState,
20
+ controllerRef.current.getState
21
+ );
22
+ return {
23
+ ...state,
24
+ send: controllerRef.current.send,
25
+ stop: controllerRef.current.stop,
26
+ retry: controllerRef.current.retry,
27
+ setInput: controllerRef.current.setInput,
28
+ clear: controllerRef.current.clear
29
+ };
30
+ }
31
+ function ChatContainer({ children }) {
32
+ return /* @__PURE__ */ jsxRuntime.jsx(ink.Box, { flexDirection: "column", gap: 1, children });
33
+ }
34
+ function roleColor(role) {
35
+ switch (role) {
36
+ case "assistant":
37
+ return "cyan";
38
+ case "user":
39
+ return "green";
40
+ case "system":
41
+ return "yellow";
42
+ case "tool":
43
+ return "magenta";
44
+ default:
45
+ return "white";
46
+ }
47
+ }
48
+ function Message({ message }) {
49
+ return /* @__PURE__ */ jsxRuntime.jsxs(ink.Box, { flexDirection: "column", children: [
50
+ /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { bold: true, color: roleColor(message.role), children: message.role.toUpperCase() }),
51
+ /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { children: message.content || (message.status === "streaming" ? "..." : "") })
52
+ ] });
53
+ }
54
+ function InputBar({ chat, placeholder = "Type a message...", disabled = false }) {
55
+ ink.useInput((input, key) => {
56
+ if (disabled || chat.status === "streaming") return;
57
+ if (key.return) {
58
+ if (chat.input.trim()) {
59
+ void chat.send(chat.input);
60
+ }
61
+ return;
62
+ }
63
+ if (key.backspace || key.delete) {
64
+ chat.setInput(chat.input.slice(0, -1));
65
+ return;
66
+ }
67
+ if (input && !key.ctrl && !key.meta) {
68
+ chat.setInput(`${chat.input}${input}`);
69
+ }
70
+ });
71
+ return /* @__PURE__ */ jsxRuntime.jsxs(ink.Box, { flexDirection: "column", children: [
72
+ /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { dimColor: true, children: placeholder }),
73
+ /* @__PURE__ */ jsxRuntime.jsxs(ink.Text, { color: disabled ? "gray" : "white", children: [
74
+ "> ",
75
+ chat.input
76
+ ] })
77
+ ] });
78
+ }
79
+ function ToolCallView({ toolCall, expanded = false }) {
80
+ return /* @__PURE__ */ jsxRuntime.jsxs(ink.Box, { flexDirection: "column", borderStyle: "round", paddingX: 1, children: [
81
+ /* @__PURE__ */ jsxRuntime.jsxs(ink.Text, { color: "magenta", children: [
82
+ "Tool: ",
83
+ toolCall.name,
84
+ " [",
85
+ toolCall.status,
86
+ "]"
87
+ ] }),
88
+ expanded ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
89
+ /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { dimColor: true, children: JSON.stringify(toolCall.args) }),
90
+ toolCall.result ? /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { children: toolCall.result }) : null,
91
+ toolCall.error ? /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { color: "red", children: toolCall.error }) : null
92
+ ] }) : null
93
+ ] });
94
+ }
95
+ function ThinkingIndicator({ visible, label = "Thinking..." }) {
96
+ if (!visible) return null;
97
+ return /* @__PURE__ */ jsxRuntime.jsx(ink.Text, { color: "yellow", children: label });
98
+ }
99
+
100
+ Object.defineProperty(exports, "createChatController", {
101
+ enumerable: true,
102
+ get: function () { return core.createChatController; }
103
+ });
104
+ Object.defineProperty(exports, "createFileMemory", {
105
+ enumerable: true,
106
+ get: function () { return core.createFileMemory; }
107
+ });
108
+ Object.defineProperty(exports, "createInMemoryMemory", {
109
+ enumerable: true,
110
+ get: function () { return core.createInMemoryMemory; }
111
+ });
112
+ Object.defineProperty(exports, "createLocalStorageMemory", {
113
+ enumerable: true,
114
+ get: function () { return core.createLocalStorageMemory; }
115
+ });
116
+ Object.defineProperty(exports, "createStaticRetriever", {
117
+ enumerable: true,
118
+ get: function () { return core.createStaticRetriever; }
119
+ });
120
+ Object.defineProperty(exports, "formatRetrievedDocuments", {
121
+ enumerable: true,
122
+ get: function () { return core.formatRetrievedDocuments; }
123
+ });
124
+ exports.ChatContainer = ChatContainer;
125
+ exports.InputBar = InputBar;
126
+ exports.Message = Message;
127
+ exports.ThinkingIndicator = ThinkingIndicator;
128
+ exports.ToolCallView = ToolCallView;
129
+ exports.useChat = useChat;
130
+ //# sourceMappingURL=index.cjs.map
131
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx"],"names":["useRef","createChatController","useEffect","useSyncExternalStore","Box","jsxs","jsx","Text","useInput","Fragment"],"mappings":";;;;;;;;AAMO,SAAS,QAAQ,MAAA,EAAgC;AACtD,EAAA,MAAM,aAAA,GAAgBA,aAA8B,IAAI,CAAA;AAExD,EAAA,IAAI,CAAC,cAAc,OAAA,EAAS;AAC1B,IAAA,aAAA,CAAc,OAAA,GAAUC,0BAAqB,MAAM,CAAA;AAAA,EACrD;AAEA,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,aAAA,CAAc,OAAA,EAAS,aAAa,MAAM,CAAA;AAAA,EAC5C,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,MAAM,KAAA,GAAQC,0BAAA;AAAA,IACZ,cAAc,OAAA,CAAQ,SAAA;AAAA,IACtB,cAAc,OAAA,CAAQ,QAAA;AAAA,IACtB,cAAc,OAAA,CAAQ;AAAA,GACxB;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,KAAA;AAAA,IACH,IAAA,EAAM,cAAc,OAAA,CAAQ,IAAA;AAAA,IAC5B,IAAA,EAAM,cAAc,OAAA,CAAQ,IAAA;AAAA,IAC5B,KAAA,EAAO,cAAc,OAAA,CAAQ,KAAA;AAAA,IAC7B,QAAA,EAAU,cAAc,OAAA,CAAQ,QAAA;AAAA,IAChC,KAAA,EAAO,cAAc,OAAA,CAAQ;AAAA,GAC/B;AACF;ACxBO,SAAS,aAAA,CAAc,EAAE,QAAA,EAAS,EAAuB;AAC9D,EAAA,sCACGC,OAAA,EAAA,EAAI,aAAA,EAAc,QAAA,EAAS,GAAA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;AAAA,sBAAAH,cAAAA,CAACC,UAAA,EAAK,QAAA,EAAQ,MAAE,QAAA,EAAA,IAAA,CAAK,SAAA,CAAU,QAAA,CAAS,IAAI,CAAA,EAAE,CAAA;AAAA,MAC7C,QAAA,CAAS,yBAASD,cAAAA,CAACC,UAAA,EAAM,QAAA,EAAA,QAAA,CAAS,QAAO,CAAA,GAAU,IAAA;AAAA,MACnD,QAAA,CAAS,KAAA,mBAAQD,cAAAA,CAACC,QAAAA,EAAA,EAAK,KAAA,EAAM,KAAA,EAAO,QAAA,EAAA,QAAA,CAAS,KAAA,EAAM,CAAA,GAAU;AAAA,KAAA,EAChE,CAAA,GACE;AAAA,GAAA,EACN,CAAA;AAEJ;AChBO,SAAS,iBAAA,CAAkB,EAAE,OAAA,EAAS,KAAA,GAAQ,eAAc,EAA2B;AAC5F,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AACrB,EAAA,uBAAOD,cAAAA,CAACC,QAAAA,EAAA,EAAK,KAAA,EAAM,UAAU,QAAA,EAAA,KAAA,EAAM,CAAA;AACrC","file":"index.cjs","sourcesContent":["// NOTE: This hook is identical in @agentskit/react and @agentskit/ink.\n// Changes here must be mirrored in packages/react/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n }\n}\n","import React, { type ReactNode } from 'react'\nimport { Box } from 'ink'\n\nexport interface ChatContainerProps {\n children: ReactNode\n}\n\nexport function ChatContainer({ children }: ChatContainerProps) {\n return (\n <Box flexDirection=\"column\" gap={1}>\n {children}\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text } from 'ink'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n}\n\nfunction roleColor(role: MessageType['role']) {\n switch (role) {\n case 'assistant':\n return 'cyan'\n case 'user':\n return 'green'\n case 'system':\n return 'yellow'\n case 'tool':\n return 'magenta'\n default:\n return 'white'\n }\n}\n\nexport function Message({ message }: MessageProps) {\n return (\n <Box flexDirection=\"column\">\n <Text bold color={roleColor(message.role)}>\n {message.role.toUpperCase()}\n </Text>\n <Text>{message.content || (message.status === 'streaming' ? '...' : '')}</Text>\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text, useInput } from 'ink'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n useInput((input, key) => {\n if (disabled || chat.status === 'streaming') return\n\n if (key.return) {\n if (chat.input.trim()) {\n void chat.send(chat.input)\n }\n return\n }\n\n if (key.backspace || key.delete) {\n chat.setInput(chat.input.slice(0, -1))\n return\n }\n\n if (input && !key.ctrl && !key.meta) {\n chat.setInput(`${chat.input}${input}`)\n }\n })\n\n return (\n <Box flexDirection=\"column\">\n <Text dimColor>{placeholder}</Text>\n <Text color={disabled ? 'gray' : 'white'}>\n &gt; {chat.input}\n </Text>\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text } from 'ink'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n expanded?: boolean\n}\n\nexport function ToolCallView({ toolCall, expanded = false }: ToolCallViewProps) {\n return (\n <Box flexDirection=\"column\" borderStyle=\"round\" paddingX={1}>\n <Text color=\"magenta\">\n Tool: {toolCall.name} [{toolCall.status}]\n </Text>\n {expanded ? (\n <>\n <Text dimColor>{JSON.stringify(toolCall.args)}</Text>\n {toolCall.result ? <Text>{toolCall.result}</Text> : null}\n {toolCall.error ? <Text color=\"red\">{toolCall.error}</Text> : null}\n </>\n ) : null}\n </Box>\n )\n}\n","import React from 'react'\nimport { Text } from 'ink'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n return <Text color=\"yellow\">{label}</Text>\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { ChatConfig, ChatReturn, Message as Message$1, ToolCall } from '@agentskit/core';
2
+ export { AdapterContext, AdapterFactory, AdapterRequest, ChatConfig, ChatController, ChatMemory, ChatReturn, ChatState, MaybePromise, MemoryRecord, MessageRole, MessageStatus, Message as MessageType, RetrievedDocument, Retriever, RetrieverRequest, StreamChunk, StreamSource, StreamStatus, StreamToolCallPayload, ToolCall, ToolCallHandlerContext, ToolCallStatus, ToolDefinition, ToolExecutionContext, UseStreamOptions, UseStreamReturn, createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ declare function useChat(config: ChatConfig): ChatReturn;
7
+
8
+ interface ChatContainerProps {
9
+ children: ReactNode;
10
+ }
11
+ declare function ChatContainer({ children }: ChatContainerProps): react_jsx_runtime.JSX.Element;
12
+
13
+ interface MessageProps {
14
+ message: Message$1;
15
+ }
16
+ declare function Message({ message }: MessageProps): react_jsx_runtime.JSX.Element;
17
+
18
+ interface InputBarProps {
19
+ chat: ChatReturn;
20
+ placeholder?: string;
21
+ disabled?: boolean;
22
+ }
23
+ declare function InputBar({ chat, placeholder, disabled }: InputBarProps): react_jsx_runtime.JSX.Element;
24
+
25
+ interface ToolCallViewProps {
26
+ toolCall: ToolCall;
27
+ expanded?: boolean;
28
+ }
29
+ declare function ToolCallView({ toolCall, expanded }: ToolCallViewProps): react_jsx_runtime.JSX.Element;
30
+
31
+ interface ThinkingIndicatorProps {
32
+ visible: boolean;
33
+ label?: string;
34
+ }
35
+ declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
36
+
37
+ export { ChatContainer, type ChatContainerProps, InputBar, type InputBarProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, useChat };
@@ -0,0 +1,37 @@
1
+ import { ChatConfig, ChatReturn, Message as Message$1, ToolCall } from '@agentskit/core';
2
+ export { AdapterContext, AdapterFactory, AdapterRequest, ChatConfig, ChatController, ChatMemory, ChatReturn, ChatState, MaybePromise, MemoryRecord, MessageRole, MessageStatus, Message as MessageType, RetrievedDocument, Retriever, RetrieverRequest, StreamChunk, StreamSource, StreamStatus, StreamToolCallPayload, ToolCall, ToolCallHandlerContext, ToolCallStatus, ToolDefinition, ToolExecutionContext, UseStreamOptions, UseStreamReturn, createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ declare function useChat(config: ChatConfig): ChatReturn;
7
+
8
+ interface ChatContainerProps {
9
+ children: ReactNode;
10
+ }
11
+ declare function ChatContainer({ children }: ChatContainerProps): react_jsx_runtime.JSX.Element;
12
+
13
+ interface MessageProps {
14
+ message: Message$1;
15
+ }
16
+ declare function Message({ message }: MessageProps): react_jsx_runtime.JSX.Element;
17
+
18
+ interface InputBarProps {
19
+ chat: ChatReturn;
20
+ placeholder?: string;
21
+ disabled?: boolean;
22
+ }
23
+ declare function InputBar({ chat, placeholder, disabled }: InputBarProps): react_jsx_runtime.JSX.Element;
24
+
25
+ interface ToolCallViewProps {
26
+ toolCall: ToolCall;
27
+ expanded?: boolean;
28
+ }
29
+ declare function ToolCallView({ toolCall, expanded }: ToolCallViewProps): react_jsx_runtime.JSX.Element;
30
+
31
+ interface ThinkingIndicatorProps {
32
+ visible: boolean;
33
+ label?: string;
34
+ }
35
+ declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
36
+
37
+ export { ChatContainer, type ChatContainerProps, InputBar, type InputBarProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, useChat };
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { createChatController } from '@agentskit/core';
2
+ export { createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
3
+ import { useRef, useEffect, useSyncExternalStore } from 'react';
4
+ import { Box, Text, useInput } from 'ink';
5
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
+
7
+ // src/index.ts
8
+ function useChat(config) {
9
+ const controllerRef = useRef(null);
10
+ if (!controllerRef.current) {
11
+ controllerRef.current = createChatController(config);
12
+ }
13
+ useEffect(() => {
14
+ controllerRef.current?.updateConfig(config);
15
+ }, [config]);
16
+ const state = useSyncExternalStore(
17
+ controllerRef.current.subscribe,
18
+ controllerRef.current.getState,
19
+ controllerRef.current.getState
20
+ );
21
+ return {
22
+ ...state,
23
+ send: controllerRef.current.send,
24
+ stop: controllerRef.current.stop,
25
+ retry: controllerRef.current.retry,
26
+ setInput: controllerRef.current.setInput,
27
+ clear: controllerRef.current.clear
28
+ };
29
+ }
30
+ function ChatContainer({ children }) {
31
+ return /* @__PURE__ */ jsx(Box, { flexDirection: "column", gap: 1, children });
32
+ }
33
+ function roleColor(role) {
34
+ switch (role) {
35
+ case "assistant":
36
+ return "cyan";
37
+ case "user":
38
+ return "green";
39
+ case "system":
40
+ return "yellow";
41
+ case "tool":
42
+ return "magenta";
43
+ default:
44
+ return "white";
45
+ }
46
+ }
47
+ function Message({ message }) {
48
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
49
+ /* @__PURE__ */ jsx(Text, { bold: true, color: roleColor(message.role), children: message.role.toUpperCase() }),
50
+ /* @__PURE__ */ jsx(Text, { children: message.content || (message.status === "streaming" ? "..." : "") })
51
+ ] });
52
+ }
53
+ function InputBar({ chat, placeholder = "Type a message...", disabled = false }) {
54
+ useInput((input, key) => {
55
+ if (disabled || chat.status === "streaming") return;
56
+ if (key.return) {
57
+ if (chat.input.trim()) {
58
+ void chat.send(chat.input);
59
+ }
60
+ return;
61
+ }
62
+ if (key.backspace || key.delete) {
63
+ chat.setInput(chat.input.slice(0, -1));
64
+ return;
65
+ }
66
+ if (input && !key.ctrl && !key.meta) {
67
+ chat.setInput(`${chat.input}${input}`);
68
+ }
69
+ });
70
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
71
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: placeholder }),
72
+ /* @__PURE__ */ jsxs(Text, { color: disabled ? "gray" : "white", children: [
73
+ "> ",
74
+ chat.input
75
+ ] })
76
+ ] });
77
+ }
78
+ function ToolCallView({ toolCall, expanded = false }) {
79
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", borderStyle: "round", paddingX: 1, children: [
80
+ /* @__PURE__ */ jsxs(Text, { color: "magenta", children: [
81
+ "Tool: ",
82
+ toolCall.name,
83
+ " [",
84
+ toolCall.status,
85
+ "]"
86
+ ] }),
87
+ expanded ? /* @__PURE__ */ jsxs(Fragment, { children: [
88
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: JSON.stringify(toolCall.args) }),
89
+ toolCall.result ? /* @__PURE__ */ jsx(Text, { children: toolCall.result }) : null,
90
+ toolCall.error ? /* @__PURE__ */ jsx(Text, { color: "red", children: toolCall.error }) : null
91
+ ] }) : null
92
+ ] });
93
+ }
94
+ function ThinkingIndicator({ visible, label = "Thinking..." }) {
95
+ if (!visible) return null;
96
+ return /* @__PURE__ */ jsx(Text, { color: "yellow", children: label });
97
+ }
98
+
99
+ export { ChatContainer, InputBar, Message, ThinkingIndicator, ToolCallView, useChat };
100
+ //# sourceMappingURL=index.js.map
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx"],"names":["Box","jsx","jsxs","Text"],"mappings":";;;;;;;AAMO,SAAS,QAAQ,MAAA,EAAgC;AACtD,EAAA,MAAM,aAAA,GAAgB,OAA8B,IAAI,CAAA;AAExD,EAAA,IAAI,CAAC,cAAc,OAAA,EAAS;AAC1B,IAAA,aAAA,CAAc,OAAA,GAAU,qBAAqB,MAAM,CAAA;AAAA,EACrD;AAEA,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,aAAA,CAAc,OAAA,EAAS,aAAa,MAAM,CAAA;AAAA,EAC5C,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,MAAM,KAAA,GAAQ,oBAAA;AAAA,IACZ,cAAc,OAAA,CAAQ,SAAA;AAAA,IACtB,cAAc,OAAA,CAAQ,QAAA;AAAA,IACtB,cAAc,OAAA,CAAQ;AAAA,GACxB;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,KAAA;AAAA,IACH,IAAA,EAAM,cAAc,OAAA,CAAQ,IAAA;AAAA,IAC5B,IAAA,EAAM,cAAc,OAAA,CAAQ,IAAA;AAAA,IAC5B,KAAA,EAAO,cAAc,OAAA,CAAQ,KAAA;AAAA,IAC7B,QAAA,EAAU,cAAc,OAAA,CAAQ,QAAA;AAAA,IAChC,KAAA,EAAO,cAAc,OAAA,CAAQ;AAAA,GAC/B;AACF;ACxBO,SAAS,aAAA,CAAc,EAAE,QAAA,EAAS,EAAuB;AAC9D,EAAA,2BACG,GAAA,EAAA,EAAI,aAAA,EAAc,QAAA,EAAS,GAAA,EAAK,GAC9B,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,CAACE,MAAA,EAAK,QAAA,EAAQ,MAAE,QAAA,EAAA,IAAA,CAAK,SAAA,CAAU,QAAA,CAAS,IAAI,CAAA,EAAE,CAAA;AAAA,MAC7C,QAAA,CAAS,yBAASF,GAAAA,CAACE,MAAA,EAAM,QAAA,EAAA,QAAA,CAAS,QAAO,CAAA,GAAU,IAAA;AAAA,MACnD,QAAA,CAAS,KAAA,mBAAQF,GAAAA,CAACE,IAAAA,EAAA,EAAK,KAAA,EAAM,KAAA,EAAO,QAAA,EAAA,QAAA,CAAS,KAAA,EAAM,CAAA,GAAU;AAAA,KAAA,EAChE,CAAA,GACE;AAAA,GAAA,EACN,CAAA;AAEJ;AChBO,SAAS,iBAAA,CAAkB,EAAE,OAAA,EAAS,KAAA,GAAQ,eAAc,EAA2B;AAC5F,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AACrB,EAAA,uBAAOF,GAAAA,CAACE,IAAAA,EAAA,EAAK,KAAA,EAAM,UAAU,QAAA,EAAA,KAAA,EAAM,CAAA;AACrC","file":"index.js","sourcesContent":["// NOTE: This hook is identical in @agentskit/react and @agentskit/ink.\n// Changes here must be mirrored in packages/react/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n }\n}\n","import React, { type ReactNode } from 'react'\nimport { Box } from 'ink'\n\nexport interface ChatContainerProps {\n children: ReactNode\n}\n\nexport function ChatContainer({ children }: ChatContainerProps) {\n return (\n <Box flexDirection=\"column\" gap={1}>\n {children}\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text } from 'ink'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n}\n\nfunction roleColor(role: MessageType['role']) {\n switch (role) {\n case 'assistant':\n return 'cyan'\n case 'user':\n return 'green'\n case 'system':\n return 'yellow'\n case 'tool':\n return 'magenta'\n default:\n return 'white'\n }\n}\n\nexport function Message({ message }: MessageProps) {\n return (\n <Box flexDirection=\"column\">\n <Text bold color={roleColor(message.role)}>\n {message.role.toUpperCase()}\n </Text>\n <Text>{message.content || (message.status === 'streaming' ? '...' : '')}</Text>\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text, useInput } from 'ink'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n useInput((input, key) => {\n if (disabled || chat.status === 'streaming') return\n\n if (key.return) {\n if (chat.input.trim()) {\n void chat.send(chat.input)\n }\n return\n }\n\n if (key.backspace || key.delete) {\n chat.setInput(chat.input.slice(0, -1))\n return\n }\n\n if (input && !key.ctrl && !key.meta) {\n chat.setInput(`${chat.input}${input}`)\n }\n })\n\n return (\n <Box flexDirection=\"column\">\n <Text dimColor>{placeholder}</Text>\n <Text color={disabled ? 'gray' : 'white'}>\n &gt; {chat.input}\n </Text>\n </Box>\n )\n}\n","import React from 'react'\nimport { Box, Text } from 'ink'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n expanded?: boolean\n}\n\nexport function ToolCallView({ toolCall, expanded = false }: ToolCallViewProps) {\n return (\n <Box flexDirection=\"column\" borderStyle=\"round\" paddingX={1}>\n <Text color=\"magenta\">\n Tool: {toolCall.name} [{toolCall.status}]\n </Text>\n {expanded ? (\n <>\n <Text dimColor>{JSON.stringify(toolCall.args)}</Text>\n {toolCall.result ? <Text>{toolCall.result}</Text> : null}\n {toolCall.error ? <Text color=\"red\">{toolCall.error}</Text> : null}\n </>\n ) : null}\n </Box>\n )\n}\n","import React from 'react'\nimport { Text } from 'ink'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n return <Text color=\"yellow\">{label}</Text>\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@agentskit/ink",
3
+ "version": "0.4.0",
4
+ "description": "Ink terminal components and hooks for AgentsKit.",
5
+ "type": "module",
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
+ "dependencies": {
20
+ "ink": "^5.1.1",
21
+ "@agentskit/core": "0.4.0"
22
+ },
23
+ "peerDependencies": {
24
+ "react": ">=18.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^24.0.0",
28
+ "@types/react": "^18.3.0",
29
+ "ink-testing-library": "^4.0.0",
30
+ "react": "^18.3.1",
31
+ "tsup": "^8.5.0",
32
+ "typescript": "^5.9.2",
33
+ "vitest": "^4.1.2"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "test": "vitest run",
41
+ "lint": "tsc --noEmit",
42
+ "dev": "tsup --watch"
43
+ }
44
+ }