@arki-moe/agent-ts 5.3.0 → 6.0.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
@@ -13,7 +13,6 @@ const getTimeTool: Tool = {
13
13
  name: "get_time",
14
14
  description: "Get the current time in ISO format",
15
15
  parameters: { type: "object", properties: {} },
16
- data: { category: "time" },
17
16
  execute: (_args, _agent) => new Date().toISOString(),
18
17
  };
19
18
 
@@ -38,6 +37,10 @@ const result = await agent.run("What time is it?");
38
37
  console.log(result.messages);
39
38
  console.log(result.usage, result.usageSum);
40
39
 
40
+ // run also accepts multiple user messages or Message objects
41
+ await agent.run(["Hello", "What's next?"]);
42
+ await agent.run({ role: Role.System, content: "You are brief." });
43
+
41
44
  // context is a public property that can be read directly
42
45
  console.log(agent.context);
43
46
  ```
@@ -58,6 +61,7 @@ When `apiKey` is not provided in config, adapters read from the corresponding en
58
61
  - `agent.context` - Public property, complete conversation history
59
62
  - `agent.registerTool(tool)` - Register tool
60
63
  - `agent.run(message)` - Execute tool chain automatically, returns `{ messages, usage, usageSum }`
64
+ - `message` can be `string | string[] | Message | Message[]`
61
65
 
62
66
  ### Config
63
67
 
@@ -77,7 +81,7 @@ When `apiKey` is not provided in config, adapters read from the corresponding en
77
81
 
78
82
  `onToolCall` receives parsed JSON args and can mutate them before execution. Returning `false` skips the tool call and does not emit a `ToolResult` message.
79
83
 
80
- `tool.data` is a local JSON metadata bag for your own use and is not sent to adapters.
84
+ `Role.ToolCall` supports an optional `data` field as a local JSON metadata bag for your own use and is not sent to adapters.
81
85
 
82
86
  `isAbort` is polled on the hot path (including streaming). When it returns `true`, `agent.run` stops and returns whatever messages it has so far. Streaming abort returns a partial AI message with `isPartial: true`.
83
87
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { AgentConfig, AgentLike, Context, Message, Tool, Usage } from "./types";
1
+ import type { AgentConfig, AgentLike, Context, Message, RunInput, Tool, Usage } from "./types";
2
2
  export { openaiAdapter } from "./adapter/openai";
3
3
  export { openrouterAdapter } from "./adapter/openrouter";
4
4
  export { selfhostChatCompletionsAdapter } from "./adapter/selfhost_chat_completions";
5
- export type { Adapter, AgentConfig, AgentLike, Context, Message, Tool, Usage, AdapterResult } from "./types";
5
+ export type { Adapter, AgentConfig, AgentLike, Context, Message, RunInput, Tool, Usage, AdapterResult } from "./types";
6
6
  export { Role } from "./types";
7
7
  export declare class Agent implements AgentLike {
8
8
  context: Context;
@@ -15,9 +15,29 @@ export declare class Agent implements AgentLike {
15
15
  private onToolResult?;
16
16
  constructor(adapterName: string, config: AgentConfig);
17
17
  registerTool(tool: Tool): void;
18
+ run(message: RunInput): Promise<{
19
+ messages: Message[];
20
+ usage?: Usage;
21
+ usageSum?: Usage;
22
+ }>;
18
23
  run(message: string): Promise<{
19
24
  messages: Message[];
20
25
  usage?: Usage;
21
26
  usageSum?: Usage;
22
27
  }>;
28
+ run(message: string[]): Promise<{
29
+ messages: Message[];
30
+ usage?: Usage;
31
+ usageSum?: Usage;
32
+ }>;
33
+ run(message: Message): Promise<{
34
+ messages: Message[];
35
+ usage?: Usage;
36
+ usageSum?: Usage;
37
+ }>;
38
+ run(message: Message[]): Promise<{
39
+ messages: Message[];
40
+ usage?: Usage;
41
+ usageSum?: Usage;
42
+ }>;
23
43
  }
package/dist/index.js CHANGED
@@ -19,6 +19,19 @@ const adapters = {
19
19
  openrouter: openrouter_1.openrouterAdapter,
20
20
  selfhost_chat_completions: selfhost_chat_completions_1.selfhostChatCompletionsAdapter,
21
21
  };
22
+ const normalizeRunInput = (input) => {
23
+ if (typeof input === "string")
24
+ return [{ role: types_1.Role.User, content: input }];
25
+ if (Array.isArray(input)) {
26
+ if (input.length === 0)
27
+ return [];
28
+ if (typeof input[0] === "string") {
29
+ return input.map((content) => ({ role: types_1.Role.User, content }));
30
+ }
31
+ return input;
32
+ }
33
+ return [input];
34
+ };
22
35
  class Agent {
23
36
  constructor(adapterName, config) {
24
37
  this.context = [];
@@ -47,9 +60,11 @@ class Agent {
47
60
  const pushToSession = (msgs) => {
48
61
  sessionContext.push(...msgs);
49
62
  };
50
- const userMessage = { role: types_1.Role.User, content: message };
51
- pushToSession([userMessage]);
52
- persistToContext([userMessage]);
63
+ const inputMessages = normalizeRunInput(message);
64
+ if (inputMessages.length === 0)
65
+ return { messages: [] };
66
+ pushToSession(inputMessages);
67
+ persistToContext(inputMessages);
53
68
  const addUsage = (next) => {
54
69
  if (!next)
55
70
  return;
package/dist/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export type Message = {
20
20
  toolName: string;
21
21
  callId: string;
22
22
  argsText: string;
23
+ data?: Record<string, unknown>;
23
24
  } | {
24
25
  role: Role.ToolResult;
25
26
  callId: string;
@@ -27,6 +28,7 @@ export type Message = {
27
28
  isError?: boolean;
28
29
  };
29
30
  export type Context = Message[];
31
+ export type RunInput = string | string[] | Message | Message[];
30
32
  export type Usage = {
31
33
  promptTokens: number;
32
34
  completionTokens: number;
@@ -35,7 +37,7 @@ export type Usage = {
35
37
  export interface AgentLike {
36
38
  context: Context;
37
39
  registerTool: (tool: Tool) => void;
38
- run: (message: string) => Promise<{
40
+ run: (message: RunInput) => Promise<{
39
41
  messages: Message[];
40
42
  usage?: Usage;
41
43
  usageSum?: Usage;
@@ -45,7 +47,6 @@ export type Tool = {
45
47
  name: string;
46
48
  description: string;
47
49
  parameters: unknown;
48
- data?: Record<string, unknown>;
49
50
  execute: (args: unknown, agent: AgentLike) => Promise<unknown> | unknown;
50
51
  };
51
52
  export type AgentConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arki-moe/agent-ts",
3
- "version": "5.3.0",
3
+ "version": "6.0.0",
4
4
  "description": "Minimal Agent library, zero dependencies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",