@joplo-app/kit 0.1.3 → 0.2.1
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/dist/index.d.ts +78 -3
- package/dist/index.js +31 -0
- package/dist/node.js +2 -2
- package/dist/ui.d.ts +19 -0
- package/dist/ui.js +17 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -86,11 +86,28 @@ export declare const question: (text: string, opts?: {
|
|
|
86
86
|
severity?: QuestionDef["severity"];
|
|
87
87
|
refs?: string[];
|
|
88
88
|
}) => QuestionDef;
|
|
89
|
+
/**
|
|
90
|
+
* 角色(D56):故事里的一个人。在 feature.roles 里用键声明,层级用 layer(…, { role: '键' }) 标明这是谁的画面,
|
|
91
|
+
* 过渡卡用 .card('…', { role: '键' }) 切到这个人。color 缺省按声明顺序自动分配。
|
|
92
|
+
* roles: { xiaoyu: role('小雨', { desc: '发起露营的人' }), ajie: role('阿杰', { desc: '被拉进来的朋友' }) }
|
|
93
|
+
*/
|
|
94
|
+
export type RoleDef = {
|
|
95
|
+
kind: 'role';
|
|
96
|
+
name: string;
|
|
97
|
+
desc?: string;
|
|
98
|
+
color?: string;
|
|
99
|
+
source?: string;
|
|
100
|
+
};
|
|
101
|
+
export declare const role: (name: string, opts?: {
|
|
102
|
+
desc?: string;
|
|
103
|
+
color?: string;
|
|
104
|
+
}) => RoleDef;
|
|
89
105
|
export type FeatureDef = {
|
|
90
106
|
kind: 'feature';
|
|
91
107
|
name: string;
|
|
92
108
|
goal: string;
|
|
93
|
-
|
|
109
|
+
/** 角色:旧写法是名字数组(只作说明);写成 { 键: role('名字') } 才能被层级和过渡卡引用。 */
|
|
110
|
+
roles?: string[] | Record<string, RoleDef>;
|
|
94
111
|
constraints?: Record<string, string | {
|
|
95
112
|
text: string;
|
|
96
113
|
hard?: boolean;
|
|
@@ -153,6 +170,22 @@ export type EffectDef = {
|
|
|
153
170
|
type: 'trace';
|
|
154
171
|
ids: string[];
|
|
155
172
|
mode: 'ok' | 'fail' | 'skip';
|
|
173
|
+
} | {
|
|
174
|
+
kind: 'effect';
|
|
175
|
+
type: 'stream';
|
|
176
|
+
path: string;
|
|
177
|
+
value: string;
|
|
178
|
+
} | {
|
|
179
|
+
kind: 'effect';
|
|
180
|
+
type: 'fork';
|
|
181
|
+
label: string;
|
|
182
|
+
scenario: string;
|
|
183
|
+
} | {
|
|
184
|
+
kind: 'effect';
|
|
185
|
+
type: 'mark';
|
|
186
|
+
target: string;
|
|
187
|
+
kindOf: 'circle' | 'underline' | 'box' | 'arrow';
|
|
188
|
+
note?: string;
|
|
156
189
|
};
|
|
157
190
|
export declare const set: (target: Bind, value: Json) => EffectDef;
|
|
158
191
|
export declare const push: (target: Bind, value: Json) => EffectDef;
|
|
@@ -162,6 +195,19 @@ export declare const toast: ((text: string) => EffectDef) & {
|
|
|
162
195
|
error: (text: string) => EffectDef;
|
|
163
196
|
info: (text: string) => EffectDef;
|
|
164
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* 流式输出(D56):和 set 一样把文字写进状态,播放到这一步时绑定它的文字逐字出现(像模型在输出)。
|
|
200
|
+
* 跳到这一步、截图、发布站静态查看时直接显示全文。自动播放会等输出完再进下一步。
|
|
201
|
+
* .system('助手回复', stream($.ui.reply, '周六晴,推荐去白河营地……'))
|
|
202
|
+
*/
|
|
203
|
+
export declare const stream: (target: Bind, text: string) => EffectDef;
|
|
204
|
+
/** 本步的另一条故事路线;目标是同一方案的场景键,自动播放仍走主线。 */
|
|
205
|
+
export declare const fork: (label: string, scenario: string) => EffectDef;
|
|
206
|
+
/** 本步手绘标注(下一步消失);目标隐藏或不在当前层时不画。 */
|
|
207
|
+
export declare const mark: (target: string, opts?: {
|
|
208
|
+
kind?: "circle" | "underline" | "box" | "arrow";
|
|
209
|
+
note?: string;
|
|
210
|
+
}) => EffectDef;
|
|
165
211
|
/** 跳转到另一个路径。 */
|
|
166
212
|
export declare const go: (route: string) => EffectDef;
|
|
167
213
|
/** 场景结束。 */
|
|
@@ -204,15 +250,28 @@ export type LayerDef = {
|
|
|
204
250
|
title: string;
|
|
205
251
|
tree: JNode | JNode[];
|
|
206
252
|
viewport?: 'desktop' | 'mobile';
|
|
253
|
+
role?: string;
|
|
207
254
|
source?: string;
|
|
208
255
|
};
|
|
256
|
+
/** opts.role:这一层是谁的画面(feature.roles 的键,D56);画面角落显示这个人的名牌,层级标签带上头像。 */
|
|
209
257
|
export declare const layer: (title: string, tree: JNode | JNode[], opts?: {
|
|
210
258
|
viewport?: "desktop" | "mobile";
|
|
259
|
+
role?: string;
|
|
211
260
|
}) => LayerDef;
|
|
212
261
|
/** 步骤参数:字符串是字幕(可省略,省略时自动生成),其余是效果。 */
|
|
213
262
|
export type StepArg = string | EffectDef;
|
|
263
|
+
/**
|
|
264
|
+
* 过渡卡(D56)的内容:整屏一句大字,用于开场、收尾、时间跳跃(「3 天后」)和换人。
|
|
265
|
+
* sub:小一号的补充;points:收尾时列几条要点;role:换到哪个人(feature.roles 的键),卡片显示这个人,
|
|
266
|
+
* 卡片之后导演切到这个人的层级。
|
|
267
|
+
*/
|
|
268
|
+
export type CardOpts = {
|
|
269
|
+
sub?: string;
|
|
270
|
+
points?: string[];
|
|
271
|
+
role?: string;
|
|
272
|
+
};
|
|
214
273
|
export type StepDef = {
|
|
215
|
-
kind: 'user' | 'system';
|
|
274
|
+
kind: 'user' | 'system' | 'card';
|
|
216
275
|
action: {
|
|
217
276
|
type: 'click';
|
|
218
277
|
target: string;
|
|
@@ -228,12 +287,18 @@ export type StepDef = {
|
|
|
228
287
|
type: 'toggle';
|
|
229
288
|
target: string;
|
|
230
289
|
value: boolean;
|
|
290
|
+
} | {
|
|
291
|
+
type: 'press';
|
|
292
|
+
keys: string;
|
|
231
293
|
} | {
|
|
232
294
|
type: 'back';
|
|
233
295
|
} | {
|
|
234
296
|
type: 'event';
|
|
235
297
|
name: string;
|
|
236
|
-
}
|
|
298
|
+
} | ({
|
|
299
|
+
type: 'card';
|
|
300
|
+
title: string;
|
|
301
|
+
} & CardOpts);
|
|
237
302
|
caption?: string;
|
|
238
303
|
effects: EffectDef[];
|
|
239
304
|
source?: string;
|
|
@@ -263,7 +328,17 @@ export declare class Flow {
|
|
|
263
328
|
type(target: string, value: string, ...args: StepArg[]): this;
|
|
264
329
|
select(target: string, value: string, ...args: StepArg[]): this;
|
|
265
330
|
toggle(target: string, value: boolean, ...args: StepArg[]): this;
|
|
331
|
+
/** 无目标的键盘操作,例如 .press('⌘K')、.press('Enter', set(...))。 */
|
|
332
|
+
press(keys: string, ...args: StepArg[]): this;
|
|
266
333
|
back(...args: StepArg[]): this;
|
|
334
|
+
/**
|
|
335
|
+
* 过渡卡(D56):整屏一句大字,可以带效果(例如时间跳跃时 set 状态)。
|
|
336
|
+
* .card('周末一起去露营', { sub: '用营地助手规划一次两个人的露营' })
|
|
337
|
+
* .card('现在是阿杰', { role: 'ajie' })
|
|
338
|
+
* .card('出发前一天', set($.data.weather, 'rain'))
|
|
339
|
+
* .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
|
|
340
|
+
*/
|
|
341
|
+
card(title: string, ...args: (CardOpts | EffectDef)[]): this;
|
|
267
342
|
/** 系统事件,例如“请求成功(模拟)”。 */
|
|
268
343
|
system(name: string, ...args: StepArg[]): this;
|
|
269
344
|
}
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ export const question = (text, opts = {}) => ({
|
|
|
37
37
|
refs: opts.refs ?? [],
|
|
38
38
|
source: callsite(),
|
|
39
39
|
});
|
|
40
|
+
export const role = (name, opts = {}) => ({ kind: 'role', name, ...opts, source: callsite() });
|
|
40
41
|
export const feature = (f) => ({ kind: 'feature', ...f, source: callsite() });
|
|
41
42
|
export const undecided = (reason) => ({ kind: 'coverage', status: 'undecided', reason });
|
|
42
43
|
export const missing = (reason) => ({ kind: 'coverage', status: 'missing', ...(reason ? { reason } : {}) });
|
|
@@ -51,6 +52,16 @@ export const toast = Object.assign((text) => ({ kind: 'effect', type: 'toast', t
|
|
|
51
52
|
error: (text) => ({ kind: 'effect', type: 'toast', text, tone: 'error' }),
|
|
52
53
|
info: (text) => ({ kind: 'effect', type: 'toast', text, tone: 'info' }),
|
|
53
54
|
});
|
|
55
|
+
/**
|
|
56
|
+
* 流式输出(D56):和 set 一样把文字写进状态,播放到这一步时绑定它的文字逐字出现(像模型在输出)。
|
|
57
|
+
* 跳到这一步、截图、发布站静态查看时直接显示全文。自动播放会等输出完再进下一步。
|
|
58
|
+
* .system('助手回复', stream($.ui.reply, '周六晴,推荐去白河营地……'))
|
|
59
|
+
*/
|
|
60
|
+
export const stream = (target, text) => ({ kind: 'effect', type: 'stream', path: pathOf(target), value: text });
|
|
61
|
+
/** 本步的另一条故事路线;目标是同一方案的场景键,自动播放仍走主线。 */
|
|
62
|
+
export const fork = (label, scenario) => ({ kind: 'effect', type: 'fork', label, scenario });
|
|
63
|
+
/** 本步手绘标注(下一步消失);目标隐藏或不在当前层时不画。 */
|
|
64
|
+
export const mark = (target, opts = {}) => ({ kind: 'effect', type: 'mark', target, kindOf: opts.kind ?? 'circle', ...(opts.note?.trim() ? { note: opts.note.trim() } : {}) });
|
|
54
65
|
/** 跳转到另一个路径。 */
|
|
55
66
|
export const go = (route) => ({ kind: 'effect', type: 'go', route });
|
|
56
67
|
/** 场景结束。 */
|
|
@@ -83,6 +94,7 @@ export const trace = Object.assign((...ids) => ({ kind: 'effect', type: 'trace',
|
|
|
83
94
|
/** 这次没被调用:节点(以及它们之间的连线)标为 dim;不移动镜头。 */
|
|
84
95
|
skip: (...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'skip' }),
|
|
85
96
|
});
|
|
97
|
+
/** opts.role:这一层是谁的画面(feature.roles 的键,D56);画面角落显示这个人的名牌,层级标签带上头像。 */
|
|
86
98
|
export const layer = (title, tree, opts = {}) => ({ kind: 'layer', title, tree, ...opts, source: callsite() });
|
|
87
99
|
export class Flow {
|
|
88
100
|
name;
|
|
@@ -113,9 +125,28 @@ export class Flow {
|
|
|
113
125
|
toggle(target, value, ...args) {
|
|
114
126
|
return this.add('user', { type: 'toggle', target, value }, args);
|
|
115
127
|
}
|
|
128
|
+
/** 无目标的键盘操作,例如 .press('⌘K')、.press('Enter', set(...))。 */
|
|
129
|
+
press(keys, ...args) {
|
|
130
|
+
return this.add('user', { type: 'press', keys }, args);
|
|
131
|
+
}
|
|
116
132
|
back(...args) {
|
|
117
133
|
return this.add('user', { type: 'back' }, args);
|
|
118
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* 过渡卡(D56):整屏一句大字,可以带效果(例如时间跳跃时 set 状态)。
|
|
137
|
+
* .card('周末一起去露营', { sub: '用营地助手规划一次两个人的露营' })
|
|
138
|
+
* .card('现在是阿杰', { role: 'ajie' })
|
|
139
|
+
* .card('出发前一天', set($.data.weather, 'rain'))
|
|
140
|
+
* .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
|
|
141
|
+
*/
|
|
142
|
+
card(title, ...args) {
|
|
143
|
+
const effects = args.filter((a) => a.kind === 'effect');
|
|
144
|
+
const opts = Object.assign({}, ...args.filter((a) => a.kind !== 'effect'));
|
|
145
|
+
const { sub, points, role } = opts;
|
|
146
|
+
const action = { type: 'card', title, ...(sub ? { sub } : {}), ...(points?.length ? { points } : {}), ...(role ? { role } : {}) };
|
|
147
|
+
this.steps.push({ kind: 'card', action, effects, source: callsite(3) });
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
119
150
|
/** 系统事件,例如“请求成功(模拟)”。 */
|
|
120
151
|
system(name, ...args) {
|
|
121
152
|
return this.add('system', { type: 'event', name }, args);
|
package/dist/node.js
CHANGED
|
@@ -7,7 +7,7 @@ export const COMPONENT = Symbol.for('joplo.component');
|
|
|
7
7
|
export const BIND = Symbol.for('joplo.bind');
|
|
8
8
|
export function component(name) {
|
|
9
9
|
const fn = (() => {
|
|
10
|
-
throw new Error(`${name}
|
|
10
|
+
throw new Error(`${name} is a Joplo component marker and can only be used in JSX`);
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(fn, COMPONENT, { value: name });
|
|
13
13
|
Object.defineProperty(fn, 'displayName', { value: name });
|
|
@@ -41,7 +41,7 @@ export function createNode(type, rawProps, source) {
|
|
|
41
41
|
}
|
|
42
42
|
return mk('#fragment', {}, out, src);
|
|
43
43
|
}
|
|
44
|
-
throw new Error(
|
|
44
|
+
throw new Error(`Unsupported JSX type: ${String(type)}`);
|
|
45
45
|
}
|
|
46
46
|
function mk(type, props, children, source) {
|
|
47
47
|
const node = { [NODE]: true, type, props, children: children === undefined ? [] : Array.isArray(children) ? children : [children] };
|
package/dist/ui.d.ts
CHANGED
|
@@ -122,11 +122,30 @@ export declare const Progress: C;
|
|
|
122
122
|
export declare const RingProgress: C;
|
|
123
123
|
export declare const Skeleton: C;
|
|
124
124
|
export declare const Notification: C;
|
|
125
|
+
/** 简单邮件卡片,正文可放 Button。 */
|
|
126
|
+
export declare const Email: C;
|
|
127
|
+
/** 键值记录;fields 缺省时展示 value 的全部键,绑定的变化行显示前后对比。 */
|
|
128
|
+
export declare const DataCard: C;
|
|
129
|
+
/** 按 states 顺序展示完成/当前/待完成状态,labels 可替换显示文字。 */
|
|
130
|
+
export declare const StateFlow: C;
|
|
125
131
|
export declare const Modal: C;
|
|
126
132
|
export declare const Drawer: C;
|
|
127
133
|
export declare const ChatMessage: C;
|
|
128
134
|
export declare const ToolCall: C;
|
|
129
135
|
export declare const PromptInput: C;
|
|
136
|
+
/**
|
|
137
|
+
* 思考过程(D56):`<Thinking title={$.ui.thought} active={$.ui.thinking} duration="8 秒" opened>…</Thinking>`。
|
|
138
|
+
* title 是此刻在想什么(随步骤 set 变化);active 时标题闪动;结束后显示“思考了 {duration}”;opened 时展开子节点里的过程。
|
|
139
|
+
*/
|
|
140
|
+
export declare const Thinking: C;
|
|
141
|
+
/**
|
|
142
|
+
* Agent 的侧边产物(D56):`<Artifact title="露营行程.md" kind="doc" status={$.ui.planStatus} version="v2">…</Artifact>`,
|
|
143
|
+
* 子节点是产物内容(Text / List / Table / Code 等,文字可以用 stream 逐字生成)。
|
|
144
|
+
* 对话里引用它用 `<Artifact.Ref id="open_plan" title="露营行程" kind="doc" />`(可点击)。
|
|
145
|
+
*/
|
|
146
|
+
export declare const Artifact: C & {
|
|
147
|
+
Ref: C;
|
|
148
|
+
};
|
|
130
149
|
/** 终端窗口:`<Terminal title="~/work"><Terminal.Command>npx joplo skill</Terminal.Command><Terminal.Output tone="ok">…</Terminal.Output></Terminal>`。 */
|
|
131
150
|
export declare const Terminal: C & {
|
|
132
151
|
Command: C;
|
package/dist/ui.js
CHANGED
|
@@ -87,12 +87,29 @@ export const Progress = c('Progress');
|
|
|
87
87
|
export const RingProgress = c('RingProgress');
|
|
88
88
|
export const Skeleton = c('Skeleton');
|
|
89
89
|
export const Notification = c('Notification');
|
|
90
|
+
/** 简单邮件卡片,正文可放 Button。 */
|
|
91
|
+
export const Email = c('Email');
|
|
92
|
+
/** 键值记录;fields 缺省时展示 value 的全部键,绑定的变化行显示前后对比。 */
|
|
93
|
+
export const DataCard = c('DataCard');
|
|
94
|
+
/** 按 states 顺序展示完成/当前/待完成状态,labels 可替换显示文字。 */
|
|
95
|
+
export const StateFlow = c('StateFlow');
|
|
90
96
|
export const Modal = c('Modal');
|
|
91
97
|
export const Drawer = c('Drawer');
|
|
92
98
|
// ---------- AI 交互(Joplo 自有) ----------
|
|
93
99
|
export const ChatMessage = c('ChatMessage');
|
|
94
100
|
export const ToolCall = c('ToolCall');
|
|
95
101
|
export const PromptInput = c('PromptInput');
|
|
102
|
+
/**
|
|
103
|
+
* 思考过程(D56):`<Thinking title={$.ui.thought} active={$.ui.thinking} duration="8 秒" opened>…</Thinking>`。
|
|
104
|
+
* title 是此刻在想什么(随步骤 set 变化);active 时标题闪动;结束后显示“思考了 {duration}”;opened 时展开子节点里的过程。
|
|
105
|
+
*/
|
|
106
|
+
export const Thinking = c('Thinking');
|
|
107
|
+
/**
|
|
108
|
+
* Agent 的侧边产物(D56):`<Artifact title="露营行程.md" kind="doc" status={$.ui.planStatus} version="v2">…</Artifact>`,
|
|
109
|
+
* 子节点是产物内容(Text / List / Table / Code 等,文字可以用 stream 逐字生成)。
|
|
110
|
+
* 对话里引用它用 `<Artifact.Ref id="open_plan" title="露营行程" kind="doc" />`(可点击)。
|
|
111
|
+
*/
|
|
112
|
+
export const Artifact = Object.assign(c('Artifact'), { Ref: c('Artifact.Ref') });
|
|
96
113
|
// ---------- 设备外框(Joplo 自有) ----------
|
|
97
114
|
/** 终端窗口:`<Terminal title="~/work"><Terminal.Command>npx joplo skill</Terminal.Command><Terminal.Output tone="ok">…</Terminal.Output></Terminal>`。 */
|
|
98
115
|
export const Terminal = Object.assign(c('Terminal'), { Command: c('Terminal.Command'), Output: c('Terminal.Output'), Input: c('Terminal.Input') });
|