@aalis/api-agent 0.6.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/README.md +25 -0
- package/dist/index.d.ts +264 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ace Nyan <ace@acenyan.com>
|
|
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/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @aalis/api-agent
|
|
2
|
+
|
|
3
|
+
类型/接口/能力声明包(只导出 `type` 与 `*Capabilities`,不含运行时逻辑)
|
|
4
|
+
|
|
5
|
+
## 角色
|
|
6
|
+
|
|
7
|
+
类型/接口/能力声明包(只导出 `type` 与 `*Capabilities`,不含运行时逻辑)
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @aalis/api-agent
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import type { /* ... */ } from '@aalis/api-agent';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
本包为 *-api 类型包;实现见对应的运行时插件。
|
|
22
|
+
|
|
23
|
+
## 许可
|
|
24
|
+
|
|
25
|
+
见仓库根目录 LICENSE。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { ChatResponse } from '@aalis/api-llm';
|
|
2
|
+
import type { ToolCallContext, ToolDefinition } from '@aalis/api-tools';
|
|
3
|
+
import type { Context } from '@aalis/core';
|
|
4
|
+
import type { IncomingMessage, Message } from '@aalis/schema-message';
|
|
5
|
+
/**
|
|
6
|
+
* 插件分组信息(按子系统聚合,供 WebUI Dashboard 等使用)
|
|
7
|
+
*
|
|
8
|
+
* Agent 服务通过 `getPluginGroups()` 暴露当前活跃插件的分组结构,
|
|
9
|
+
* 由 dashboard 据此把插件归入对应的子系统面板。
|
|
10
|
+
*/
|
|
11
|
+
export interface PluginGroupInfo {
|
|
12
|
+
/** 分组显示名称 */
|
|
13
|
+
label: string;
|
|
14
|
+
/** 该分组包含的插件 instanceId 列表 */
|
|
15
|
+
plugins: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 消息预处理器函数
|
|
19
|
+
*
|
|
20
|
+
* 在消息到达 LLM 之前对 IncomingMessage 进行变换。
|
|
21
|
+
* 遵循洋葱模型:调用 `next()` 将控制权传递给下一个预处理器,
|
|
22
|
+
* 不调用则中断整个流程(LLM 不会被调用)。
|
|
23
|
+
*/
|
|
24
|
+
export type PreprocessorFn = (message: IncomingMessage, next: () => Promise<void>) => Promise<void>;
|
|
25
|
+
/** 已注册预处理器的元信息 */
|
|
26
|
+
export interface PreprocessorInfo {
|
|
27
|
+
/** 预处理器名称 */
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Agent 服务 —— 对话编排引擎
|
|
32
|
+
*
|
|
33
|
+
* 负责接收用户消息并编排完整的对话流程:
|
|
34
|
+
* 组装系统提示、加载历史、调用 LLM、执行工具调用循环、发出回复。
|
|
35
|
+
*
|
|
36
|
+
* 默认由 plugin-agent-default 提供。
|
|
37
|
+
* 外部插件可以注册自己的 AgentService 来完全接管或扩展对话编排逻辑。
|
|
38
|
+
*/
|
|
39
|
+
export interface AgentService {
|
|
40
|
+
/** 处理一条传入消息,完成完整的对话循环 */
|
|
41
|
+
handleMessage(message: IncomingMessage): Promise<void>;
|
|
42
|
+
/** 中止指定会话的当前生成(可选实现) */
|
|
43
|
+
abort?(sessionId: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* 注册消息预处理器
|
|
46
|
+
*
|
|
47
|
+
* 预处理器在 `agent:input:before` 阶段运行,可以修改 IncomingMessage(如将图片转文字、解析文件)。
|
|
48
|
+
* 底层通过中间件系统实现,priority 越大越先执行。
|
|
49
|
+
*/
|
|
50
|
+
registerPreprocessor?(name: string, handler: PreprocessorFn): () => void;
|
|
51
|
+
/** 获取当前所有已注册预处理器的元信息 */
|
|
52
|
+
getPreprocessors?(): PreprocessorInfo[];
|
|
53
|
+
/**
|
|
54
|
+
* 获取 Agent 子系统的插件分组
|
|
55
|
+
*
|
|
56
|
+
* 基于 Agent 的 inject 声明,自动找出所有为 Agent 提供服务的插件,
|
|
57
|
+
* 返回分组信息供 Dashboard 使用。
|
|
58
|
+
*/
|
|
59
|
+
getPluginGroups?(): PluginGroupInfo[];
|
|
60
|
+
}
|
|
61
|
+
declare module '@aalis/core' {
|
|
62
|
+
interface HookContextMap {
|
|
63
|
+
'agent:input:before': {
|
|
64
|
+
message: IncomingMessage;
|
|
65
|
+
metadata: Record<string, unknown>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 一轮 agent 处理结束时触发(仿 Fastify `onResponse` 相位)。
|
|
69
|
+
*/
|
|
70
|
+
'agent:turn:after': {
|
|
71
|
+
message: IncomingMessage;
|
|
72
|
+
reply: string;
|
|
73
|
+
outcome: 'replied' | 'silent' | 'aborted' | 'error';
|
|
74
|
+
sessionId: string;
|
|
75
|
+
metadata: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
'agent:tool:before': {
|
|
78
|
+
name: string;
|
|
79
|
+
args: Record<string, unknown>;
|
|
80
|
+
toolCallContext: ToolCallContext;
|
|
81
|
+
};
|
|
82
|
+
'agent:tool:after': {
|
|
83
|
+
name: string;
|
|
84
|
+
result: string;
|
|
85
|
+
toolCallContext: ToolCallContext;
|
|
86
|
+
};
|
|
87
|
+
'agent:reply:before': {
|
|
88
|
+
content: string;
|
|
89
|
+
archiveContent?: string;
|
|
90
|
+
sessionId: string;
|
|
91
|
+
platform?: string;
|
|
92
|
+
userId?: string;
|
|
93
|
+
triggerType?: IncomingMessage['triggerType'];
|
|
94
|
+
/**
|
|
95
|
+
* 当中间件检测到回复无法满足约束(如 outputFormat 解析失败)时,
|
|
96
|
+
* 可将其置为 true 触发 agent 重试。agent 会按 `maxRetries` 循环重试,
|
|
97
|
+
* 用尽次数后若仍 true,会强制把 content 置空以避免错误内容外发。
|
|
98
|
+
*/
|
|
99
|
+
retryRequested?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* 重试时附加给模型的反馈系统消息内容,描述本次失败原因与修复要求。
|
|
102
|
+
* 仅在 retryRequested === true 时生效。
|
|
103
|
+
*/
|
|
104
|
+
retryFeedback?: string;
|
|
105
|
+
/**
|
|
106
|
+
* 当前已重试的次数(首次进入 hook 时为 0;agent 每次重试后递增)。
|
|
107
|
+
* 中间件用此判断「这是第几次解析这一轮的回复」。
|
|
108
|
+
*/
|
|
109
|
+
attempt?: number;
|
|
110
|
+
/**
|
|
111
|
+
* 中间件期望的最大重试次数。第一次进入 hook 时由中间件写入,agent 据此决定循环次数。
|
|
112
|
+
* 缺省视为 0(不重试)。
|
|
113
|
+
*/
|
|
114
|
+
maxRetries?: number;
|
|
115
|
+
};
|
|
116
|
+
'agent:llm:before': {
|
|
117
|
+
messages: Message[];
|
|
118
|
+
tools: ToolDefinition[];
|
|
119
|
+
sessionId?: string;
|
|
120
|
+
userId?: string;
|
|
121
|
+
platform?: string;
|
|
122
|
+
triggerType?: IncomingMessage['triggerType'];
|
|
123
|
+
/**
|
|
124
|
+
* 干跑标记:本次只为估算上下文体积(token:request 快照),不会真正调用 LLM。
|
|
125
|
+
* 昂贵/有副作用的注入者(向量检索、档案加载)据此跳过——代价是快照略微
|
|
126
|
+
* 低估这些块的体积,真实回合的统计不受影响。
|
|
127
|
+
*/
|
|
128
|
+
dryRun?: boolean;
|
|
129
|
+
};
|
|
130
|
+
'agent:llm:after': {
|
|
131
|
+
response: ChatResponse;
|
|
132
|
+
messages: Message[];
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Scoped Agent 服务,用于插件 apply() 中注册预处理器。
|
|
138
|
+
*/
|
|
139
|
+
export interface ScopedAgentService {
|
|
140
|
+
/**
|
|
141
|
+
* 注册输入预处理器。若 'agent' 服务尚未就绪,会通过 `ctx.whenService` 自动延迟。
|
|
142
|
+
*
|
|
143
|
+
* 仅当 service 提供 `registerPreprocessor` 时生效;不支持预处理器的 Agent 实现下
|
|
144
|
+
* 调用方应自行降级到 `ctx.middleware('agent:input:before', ...)`。
|
|
145
|
+
*/
|
|
146
|
+
registerPreprocessor(name: string, handler: PreprocessorFn): () => void;
|
|
147
|
+
/** 获取底层 service(未就绪时为 undefined) */
|
|
148
|
+
readonly raw: AgentService | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 获取 ScopedAgentService。
|
|
152
|
+
*/
|
|
153
|
+
export declare function useAgent(ctx: Context): ScopedAgentService;
|
|
154
|
+
declare module '@aalis/core' {
|
|
155
|
+
interface ServiceTypeMap {
|
|
156
|
+
agent: AgentService;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 提示词锚位——组装器的槽位词汇表(封闭联合,新增锚位是纯增量的类型变更):
|
|
161
|
+
*
|
|
162
|
+
* - `identity`:紧贴首条 system(persona)之后。你是谁 / 对话者是谁
|
|
163
|
+
* (档案、关系、行为准则)。
|
|
164
|
+
* - `knowledge`:头部 system 区末尾,先于 context。可用能力与操作知识
|
|
165
|
+
* (技能清单、已激活技能正文)。
|
|
166
|
+
* - `context`:头部 system 区末尾,居 knowledge 之后。检索到的对话上下文
|
|
167
|
+
* (向量记忆、摘要、跨会话历史、文件清单)。
|
|
168
|
+
* - `turn-hint`:最后一条 user 消息之前。仅与当前这一轮相关的即时提示
|
|
169
|
+
* (群聊时间线提醒、特殊事件说明)。messages 中无 user 消息时该槽弃置。
|
|
170
|
+
*
|
|
171
|
+
* 同槽内多块按全局键码元序排布——**顺序确定但无语义**,契约要求同槽贡献
|
|
172
|
+
* 互不依赖先后;若两块内容有顺序依赖,它们应属于同一个贡献(build 返回
|
|
173
|
+
* 数组,块间保序)。
|
|
174
|
+
*/
|
|
175
|
+
export type PromptAnchor = 'identity' | 'knowledge' | 'context' | 'turn-hint';
|
|
176
|
+
/**
|
|
177
|
+
* build 的只读视图——贡献者能看到的全部信息。
|
|
178
|
+
*
|
|
179
|
+
* 贡献者不掌握控制流:看不到其他贡献的产出,不能改写 messages,
|
|
180
|
+
* 不能影响排布;只能决定"这一轮交不交料、交什么"。
|
|
181
|
+
*
|
|
182
|
+
* `messages` 是组装开始时的浅拷贝快照:build 之间并行执行,禁止(也无法
|
|
183
|
+
* 经由本数组)改写真实消息序列;消息对象本身未深拷贝,不要变更其字段。
|
|
184
|
+
*/
|
|
185
|
+
export interface PromptContributionView {
|
|
186
|
+
readonly sessionId?: string;
|
|
187
|
+
readonly userId?: string;
|
|
188
|
+
readonly platform?: string;
|
|
189
|
+
readonly triggerType?: IncomingMessage['triggerType'];
|
|
190
|
+
/**
|
|
191
|
+
* 干跑标记:本次只为估算上下文体积(token:request 快照),不会真正调用 LLM。
|
|
192
|
+
* 昂贵/有副作用的构建(向量检索、档案加载)据此返回 null 跳过——代价是
|
|
193
|
+
* 快照略微低估这些块的体积,真实回合的统计不受影响。
|
|
194
|
+
*/
|
|
195
|
+
readonly dryRun: boolean;
|
|
196
|
+
readonly messages: readonly Message[];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* `agent:prompt` 贡献点的 spec——经 `ctx.contribute('agent:prompt', spec)` 注册。
|
|
200
|
+
*
|
|
201
|
+
* - `id`:局部幂等键(如 'context'、`activation:${skillName}`),注册时被内核
|
|
202
|
+
* 冠 `${ctx.id}/` 前缀成全局键;全局键即物化块的 `metadata.injector`
|
|
203
|
+
* (token 统计 / 裁剪 / 幂等识别的归属标识)。
|
|
204
|
+
* - `build`:每次 LLM 调用前被组装器调用(含工具循环各轮;已物化过的贡献
|
|
205
|
+
* 按全局键跳过,不会重复 build)。返回 null = 本轮不交料;返回数组 =
|
|
206
|
+
* 多块,块间保序、共用同一全局键。**抛错只导致本贡献缺席,不影响他人、
|
|
207
|
+
* 不中断流程**(与 hooks 的上溯中断相反,这是设计意图)。
|
|
208
|
+
*/
|
|
209
|
+
export interface PromptContribution {
|
|
210
|
+
id: string;
|
|
211
|
+
anchor: PromptAnchor;
|
|
212
|
+
build(view: PromptContributionView): string | readonly string[] | null | Promise<string | readonly string[] | null>;
|
|
213
|
+
}
|
|
214
|
+
declare module '@aalis/core' {
|
|
215
|
+
interface ContributionPointMap {
|
|
216
|
+
'agent:prompt': PromptContribution;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** token:usage 事件的 12 桶 prompt 构成明细(单位:token 数) */
|
|
220
|
+
export interface TokenUsageBreakdown {
|
|
221
|
+
system: number;
|
|
222
|
+
persona: number;
|
|
223
|
+
memorySummary: number;
|
|
224
|
+
memoryVector: number;
|
|
225
|
+
skills: number;
|
|
226
|
+
platform: number;
|
|
227
|
+
subtask: number;
|
|
228
|
+
systemOther: number;
|
|
229
|
+
/** systemOther 的按注入者明细(injector 标签 → tokens),诊断预算争抢用 */
|
|
230
|
+
injectors?: Record<string, number>;
|
|
231
|
+
history: number;
|
|
232
|
+
toolResults: number;
|
|
233
|
+
toolDefs: number;
|
|
234
|
+
reservedForReply: number;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* agent 每次 LLM 调用后 emit 的 prompt 预算快照。
|
|
238
|
+
*
|
|
239
|
+
* 发射方:plugin-agent;已知消费方:plugin-webui-server(面板渲染)、
|
|
240
|
+
* plugin-memory-summary(预压缩触发)、plugin-prompt-budget(AI 自检工具)。
|
|
241
|
+
*/
|
|
242
|
+
export interface TokenUsageEvent {
|
|
243
|
+
sessionId: string;
|
|
244
|
+
platform: string;
|
|
245
|
+
contextWindow: number;
|
|
246
|
+
maxTokens: number;
|
|
247
|
+
tokenBudget: number;
|
|
248
|
+
used: number;
|
|
249
|
+
usageRatio: number;
|
|
250
|
+
breakdown: TokenUsageBreakdown;
|
|
251
|
+
}
|
|
252
|
+
declare module '@aalis/core' {
|
|
253
|
+
interface AalisEvents {
|
|
254
|
+
'token:usage': [usage: TokenUsageEvent];
|
|
255
|
+
/**
|
|
256
|
+
* 请求 agent 重发某会话的最新 token:usage 快照。
|
|
257
|
+
* 发射方:plugin-webui-server(客户端刷新/重连时);消费方:plugin-agent。
|
|
258
|
+
*/
|
|
259
|
+
'token:request': [req: {
|
|
260
|
+
sessionId: string;
|
|
261
|
+
}];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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AE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC/C;CACF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ----- Agent 服务接口(完整定义)-----
|
|
2
|
+
//
|
|
3
|
+
// 提供 AgentService 完整契约 + agent:* 钩子声明。
|
|
4
|
+
// 默认实现由 @aalis/plugin-agent 提供。
|
|
5
|
+
//
|
|
6
|
+
// 第三方插件若要 augment HookContextMap 的 agent:* 键,需要把本包加入
|
|
7
|
+
// 依赖(或 import 一次 side-effect)以确保 TS 编译期看到 augmentation。
|
|
8
|
+
/**
|
|
9
|
+
* 获取 ScopedAgentService。
|
|
10
|
+
*/
|
|
11
|
+
export function useAgent(ctx) {
|
|
12
|
+
return {
|
|
13
|
+
registerPreprocessor(name, handler) {
|
|
14
|
+
// 持续订阅 'agent':服务每次上线都尝试挂上 preprocessor;若 service 没实现
|
|
15
|
+
// registerPreprocessor 则本次注册为 no-op,bounce 到新提供者时再尝试一次。
|
|
16
|
+
return ctx.whenService('agent', s => s.registerPreprocessor?.(name, handler));
|
|
17
|
+
},
|
|
18
|
+
get raw() {
|
|
19
|
+
return ctx.getService('agent');
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,uCAAuC;AACvC,gCAAgC;AAChC,EAAE;AACF,qDAAqD;AACrD,wDAAwD;AAuJxD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO;QACL,oBAAoB,CAAC,IAAY,EAAE,OAAuB;YACxD,sDAAsD;YACtD,wDAAwD;YACxD,OAAO,GAAG,CAAC,WAAW,CAAe,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9F,CAAC;QACD,IAAI,GAAG;YACL,OAAO,GAAG,CAAC,UAAU,CAAe,OAAO,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aalis/api-agent",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/AalisLabs/Aalis.git",
|
|
8
|
+
"directory": "packages/api-agent"
|
|
9
|
+
},
|
|
10
|
+
"author": "Ace Nyan <ace@acenyan.com>",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/AalisLabs/Aalis/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/AalisLabs/Aalis#readme",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@aalis/api-llm": ">=0.9.0 <1.0.0",
|
|
23
|
+
"@aalis/schema-message": ">=0.5.1 <1.0.0",
|
|
24
|
+
"@aalis/api-tools": ">=0.5.1 <1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"typescript": "^5.7.0",
|
|
29
|
+
"@aalis/core": "0.10.0"
|
|
30
|
+
},
|
|
31
|
+
"aalis": {
|
|
32
|
+
"types": true
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@aalis/core": ">=0.8.0 <1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"aalis",
|
|
39
|
+
"aalis-api"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"dev": "tsc --watch"
|
|
44
|
+
}
|
|
45
|
+
}
|