@webskill/sdk 0.1.4 → 0.2.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.
@@ -1,4 +1,4 @@
1
- import { _ as RenderResultRequest, o as InteractionRequest, s as InteractionResponse, v as UiBridge } from "./types-CgNC-oQu-DYrxhD3z.js";
1
+ import { _ as RenderResultRequest, o as InteractionRequest, s as InteractionResponse, v as UiBridge } from "./types-CKm5G_eQ-8W8FnP4u.js";
2
2
  //#region ../ui-react/dist/index.d.ts
3
3
  //#region src/bridgeState.d.ts
4
4
  /**
@@ -9,6 +9,8 @@ declare class ReactBridgeState implements UiBridge {
9
9
  #private;
10
10
  pending: InteractionRequest | null;
11
11
  latestResult: RenderResultRequest | null;
12
+ /** 当前流式 runId(并发 run 隔离:新 runId 重置文本) */
13
+ streamingRunId: string | null;
12
14
  streamingText: string;
13
15
  /** React useSyncExternalStore 兼容订阅 */
14
16
  subscribe: (listener: () => void) => (() => void);
@@ -16,7 +18,7 @@ declare class ReactBridgeState implements UiBridge {
16
18
  /** 组件提交/取消回调 */
17
19
  resolve(response: InteractionResponse): void;
18
20
  renderResult(input: RenderResultRequest): Promise<void>;
19
- onTextDelta(_runId: string, delta: string): Promise<void>;
21
+ onTextDelta(runId: string, delta: string): Promise<void>;
20
22
  }
21
23
  //#endregion
22
24
  //#region src/components/InteractionForm.d.ts
package/dist/ui-react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as renderMiniMarkdown, m as collectValues, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-MTc2KB03.js";
1
+ import { S as renderMiniMarkdown, m as collectValues, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-BJobG0i-.js";
2
2
  import { useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
 
@@ -10,6 +10,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
10
10
  var ReactBridgeState = class {
11
11
  pending = null;
12
12
  latestResult = null;
13
+ /** 当前流式 runId(并发 run 隔离:新 runId 重置文本) */
14
+ streamingRunId = null;
13
15
  streamingText = "";
14
16
  #listeners = /* @__PURE__ */ new Set();
15
17
  #resolvers = /* @__PURE__ */ new Map();
@@ -41,14 +43,20 @@ var ReactBridgeState = class {
41
43
  this.latestResult = input;
42
44
  this.#emit();
43
45
  }
44
- async onTextDelta(_runId, delta) {
46
+ async onTextDelta(runId, delta) {
47
+ if (this.streamingRunId !== runId) {
48
+ this.streamingRunId = runId;
49
+ this.streamingText = "";
50
+ }
45
51
  this.streamingText += delta;
46
52
  this.#emit();
47
53
  }
48
54
  };
49
- function Control({ control }) {
55
+ function Control({ control, invalid }) {
56
+ const controlId = `webskill-field-${control.name}`;
50
57
  const label = /* @__PURE__ */ jsxs("label", {
51
58
  className: "webskill-form__label",
59
+ htmlFor: controlId,
52
60
  children: [control.label, control.required ? " *" : ""]
53
61
  });
54
62
  const description = control.description ? /* @__PURE__ */ jsx("div", {
@@ -64,6 +72,8 @@ function Control({ control }) {
64
72
  description,
65
73
  /* @__PURE__ */ jsx("input", {
66
74
  type: "checkbox",
75
+ id: controlId,
76
+ "aria-invalid": invalid || void 0,
67
77
  className: "webskill-form__input",
68
78
  "data-webskill-control": control.name,
69
79
  defaultChecked: control.defaultValue === true
@@ -77,6 +87,8 @@ function Control({ control }) {
77
87
  label,
78
88
  description,
79
89
  /* @__PURE__ */ jsx("select", {
90
+ id: controlId,
91
+ "aria-invalid": invalid || void 0,
80
92
  className: "webskill-form__input",
81
93
  "data-webskill-control": control.name,
82
94
  children: (control.options ?? []).map((option, i) => /* @__PURE__ */ jsx("option", {
@@ -94,6 +106,8 @@ function Control({ control }) {
94
106
  label,
95
107
  description,
96
108
  /* @__PURE__ */ jsx("textarea", {
109
+ id: controlId,
110
+ "aria-invalid": invalid || void 0,
97
111
  className: "webskill-form__input",
98
112
  "data-webskill-control": control.name,
99
113
  defaultValue: control.defaultValue !== void 0 ? String(control.defaultValue) : ""
@@ -108,6 +122,8 @@ function Control({ control }) {
108
122
  description,
109
123
  /* @__PURE__ */ jsx("input", {
110
124
  type: control.control === "number" ? "number" : "text",
125
+ id: controlId,
126
+ "aria-invalid": invalid || void 0,
111
127
  className: "webskill-form__input",
112
128
  "data-webskill-control": control.name,
113
129
  defaultValue: control.defaultValue !== void 0 ? String(control.defaultValue) : ""
@@ -151,7 +167,12 @@ function InteractionForm({ bridge }) {
151
167
  }) : null,
152
168
  model.controls.map((control) => /* @__PURE__ */ jsxs("div", {
153
169
  className: invalid.includes(control.name) ? "webskill-form__control--invalid" : void 0,
154
- children: [/* @__PURE__ */ jsx(Control, { control }), invalid.includes(control.name) ? /* @__PURE__ */ jsx("div", {
170
+ children: [/* @__PURE__ */ jsx(Control, {
171
+ control,
172
+ invalid: invalid.includes(control.name)
173
+ }), invalid.includes(control.name) ? /* @__PURE__ */ jsx("div", {
174
+ id: `webskill-error-${control.name}`,
175
+ role: "alert",
155
176
  className: "webskill-form__error",
156
177
  children: "This field is required"
157
178
  }) : null]
package/dist/ui-vue.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { _ as RenderResultRequest, o as InteractionRequest, s as InteractionResponse, v as UiBridge } from "./types-CgNC-oQu-DYrxhD3z.js";
1
+ import { _ as RenderResultRequest, o as InteractionRequest, s as InteractionResponse, v as UiBridge } from "./types-CKm5G_eQ-8W8FnP4u.js";
2
2
  import { PropType } from "vue";
3
3
  //#region ../ui-vue/dist/index.d.ts
4
4
  //#region src/bridgeState.d.ts
5
5
  interface VueBridgeSnapshot {
6
6
  pending: InteractionRequest | null;
7
7
  latestResult: RenderResultRequest | null;
8
+ streamingRunId: string | null;
8
9
  streamingText: string;
9
10
  }
10
11
  /**
@@ -18,7 +19,7 @@ declare class VueBridgeState implements UiBridge {
18
19
  /** 组件提交/取消回调 */
19
20
  resolve(response: InteractionResponse): void;
20
21
  renderResult(input: RenderResultRequest): Promise<void>;
21
- onTextDelta(_runId: string, delta: string): Promise<void>;
22
+ onTextDelta(runId: string, delta: string): Promise<void>;
22
23
  }
23
24
  //#endregion
24
25
  //#region src/components/interactionForm.d.ts
package/dist/ui-vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as renderMiniMarkdown, m as collectValues, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-MTc2KB03.js";
1
+ import { S as renderMiniMarkdown, m as collectValues, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-BJobG0i-.js";
2
2
  import { defineComponent, h, reactive, ref } from "vue";
3
3
 
4
4
  //#region ../ui-vue/dist/index.js
@@ -10,6 +10,7 @@ var VueBridgeState = class {
10
10
  state = reactive({
11
11
  pending: null,
12
12
  latestResult: null,
13
+ streamingRunId: null,
13
14
  streamingText: ""
14
15
  });
15
16
  #resolvers = /* @__PURE__ */ new Map();
@@ -30,18 +31,28 @@ var VueBridgeState = class {
30
31
  async renderResult(input) {
31
32
  this.state.latestResult = input;
32
33
  }
33
- async onTextDelta(_runId, delta) {
34
+ async onTextDelta(runId, delta) {
35
+ if (this.state.streamingRunId !== runId) {
36
+ this.state.streamingRunId = runId;
37
+ this.state.streamingText = "";
38
+ }
34
39
  this.state.streamingText += delta;
35
40
  }
36
41
  };
37
- function renderControl(control) {
38
- const label = h("label", { class: "webskill-form__label" }, [control.label, ...control.required ? [" *"] : []]);
42
+ function renderControl(control, invalid) {
43
+ const controlId = `webskill-field-${control.name}`;
44
+ const label = h("label", {
45
+ class: "webskill-form__label",
46
+ for: controlId
47
+ }, [control.label, ...control.required ? [" *"] : []]);
39
48
  const description = control.description ? h("div", { class: "webskill-form__description" }, control.description) : null;
40
49
  let input;
41
50
  switch (control.control) {
42
51
  case "boolean":
43
52
  input = h("input", {
44
53
  type: "checkbox",
54
+ id: controlId,
55
+ "aria-invalid": invalid || void 0,
45
56
  class: "webskill-form__input",
46
57
  "data-webskill-control": control.name,
47
58
  checked: control.defaultValue === true
@@ -49,6 +60,8 @@ function renderControl(control) {
49
60
  break;
50
61
  case "select":
51
62
  input = h("select", {
63
+ id: controlId,
64
+ "aria-invalid": invalid || void 0,
52
65
  class: "webskill-form__input",
53
66
  "data-webskill-control": control.name
54
67
  }, (control.options ?? []).map((option) => h("option", {
@@ -58,6 +71,8 @@ function renderControl(control) {
58
71
  break;
59
72
  case "textarea":
60
73
  input = h("textarea", {
74
+ id: controlId,
75
+ "aria-invalid": invalid || void 0,
61
76
  class: "webskill-form__input",
62
77
  "data-webskill-control": control.name,
63
78
  value: control.defaultValue !== void 0 ? String(control.defaultValue) : ""
@@ -65,6 +80,8 @@ function renderControl(control) {
65
80
  break;
66
81
  default: input = h("input", {
67
82
  type: control.control === "number" ? "number" : "text",
83
+ id: controlId,
84
+ "aria-invalid": invalid || void 0,
68
85
  class: "webskill-form__input",
69
86
  "data-webskill-control": control.name,
70
87
  value: control.defaultValue !== void 0 ? String(control.defaultValue) : ""
@@ -113,7 +130,11 @@ const InteractionForm = defineComponent({
113
130
  }, [
114
131
  model.title ? h("div", { class: "webskill-form__title" }, model.title) : null,
115
132
  model.message && (model.kind === "form" || model.kind === "authorize") ? h("p", { class: "webskill-form__message" }, model.message) : null,
116
- ...model.controls.map((control) => h("div", { key: control.name }, [renderControl(control), invalid.value.includes(control.name) ? h("div", { class: "webskill-form__error" }, "This field is required") : null])),
133
+ ...model.controls.map((control) => h("div", { key: control.name }, [renderControl(control, invalid.value.includes(control.name)), invalid.value.includes(control.name) ? h("div", {
134
+ id: `webskill-error-${control.name}`,
135
+ role: "alert",
136
+ class: "webskill-form__error"
137
+ }, "This field is required") : null])),
117
138
  h("div", { class: "webskill-form__actions" }, [h("button", {
118
139
  type: "submit",
119
140
  class: "webskill-form__button webskill-form__button--primary"
@@ -132,20 +153,28 @@ const InteractionForm = defineComponent({
132
153
  });
133
154
  function renderBlock(block, key) {
134
155
  switch (block.type) {
135
- case "chart": return h("div", {
136
- key,
137
- onVnodeMounted: (vnode) => {
156
+ case "chart": {
157
+ const renderChart = (vnode) => {
138
158
  const el = vnode.el;
139
159
  if (el) el.replaceChildren(renderMiniChart(block.chart, el.ownerDocument));
140
- }
141
- });
142
- case "markdown": return h("div", {
143
- key,
144
- onVnodeMounted: (vnode) => {
160
+ };
161
+ return h("div", {
162
+ key,
163
+ onVnodeMounted: renderChart,
164
+ onVnodeUpdated: renderChart
165
+ });
166
+ }
167
+ case "markdown": {
168
+ const renderMd = (vnode) => {
145
169
  const el = vnode.el;
146
170
  if (el) el.replaceChildren(renderMiniMarkdown(block.text, el.ownerDocument));
147
- }
148
- });
171
+ };
172
+ return h("div", {
173
+ key,
174
+ onVnodeMounted: renderMd,
175
+ onVnodeUpdated: renderMd
176
+ });
177
+ }
149
178
  case "json": return h("pre", {
150
179
  key,
151
180
  class: "webskill-result__json"
package/dist/ui.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as RenderResultRequest, g as RenderBlock, o as InteractionRequest, r as ChartSpec, s as InteractionResponse, v as UiBridge } from "./types-CgNC-oQu-DYrxhD3z.js";
2
- import { dt as buildRenderResult } from "./index-BSS3EWY-.js";
1
+ import { _ as RenderResultRequest, g as RenderBlock, o as InteractionRequest, r as ChartSpec, s as InteractionResponse, v as UiBridge } from "./types-CKm5G_eQ-8W8FnP4u.js";
2
+ import { mt as buildRenderResult } from "./index-CySxIvRz.js";
3
3
  //#region ../ui/dist/index.d.ts
4
4
  //#region src/model/formModel.d.ts
5
5
  interface FormModel {
@@ -50,7 +50,7 @@ declare function renderMiniMarkdown(text: string, doc: Document): HTMLElement;
50
50
  //#endregion
51
51
  //#region src/chart/miniChart.d.ts
52
52
  /** 固定 8 色循环调色板 */
53
- declare const CHART_PALETTE: readonly ['#4e79a7', '#f28e2b', '#e15759', '#76b7b2', '#59a14f', '#edc948', '#b07aa1', '#ff9da7'];
53
+ declare const CHART_PALETTE: readonly ["#4e79a7", "#f28e2b", "#e15759", "#76b7b2", "#59a14f", "#edc948", "#b07aa1", "#ff9da7"];
54
54
  /**
55
55
  * ChartSpec → SVG(bar 等宽柱 + 值标签;line 折线 + 点;pie 扇形 + 图例;空数据容错)
56
56
  * @stable
@@ -77,6 +77,8 @@ declare class WebFormBridge implements UiBridge {
77
77
  styles?: boolean;
78
78
  });
79
79
  request(input: InteractionRequest): Promise<InteractionResponse>;
80
+ /** 尽力取消等待中的 request(超时后清理遗留表单) */
81
+ cancel(id: string): void;
80
82
  renderResult(input: RenderResultRequest): Promise<void>;
81
83
  progress(input: {
82
84
  runId: string;
package/dist/ui.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as buildRenderResult } from "./dist-DAn07zHu.js";
2
- import { C as renderRenderResult, D as toVercelToolInvocation, E as toOpenUiLang, S as renderMiniMarkdown, T as toA2uiMessages, _ as fromOpenUiAction, a as CHART_PALETTE, b as renderBlocks, c as OPENUI_SUBMIT_ACTION, d as WEBSKILL_STYLES_CSS, f as WebFormBridge, g as fromA2uiAction, h as ensureStyles, i as A2UI_VERSION, l as VERCEL_INTERACTION_TOOL_NAME, m as collectValues, n as A2UI_CANCEL_ACTION, o as LitRendererBridge, p as chartToTable, r as A2UI_SUBMIT_ACTION, s as OPENUI_CANCEL_ACTION, t as A2UI_BASIC_CATALOG_ID, u as VercelUiBridge, v as fromVercelToolResult, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-MTc2KB03.js";
1
+ import { w as buildRenderResult } from "./dist-BS5OpedX.js";
2
+ import { C as renderRenderResult, D as toVercelToolInvocation, E as toOpenUiLang, S as renderMiniMarkdown, T as toA2uiMessages, _ as fromOpenUiAction, a as CHART_PALETTE, b as renderBlocks, c as OPENUI_SUBMIT_ACTION, d as WEBSKILL_STYLES_CSS, f as WebFormBridge, g as fromA2uiAction, h as ensureStyles, i as A2UI_VERSION, l as VERCEL_INTERACTION_TOOL_NAME, m as collectValues, n as A2UI_CANCEL_ACTION, o as LitRendererBridge, p as chartToTable, r as A2UI_SUBMIT_ACTION, s as OPENUI_CANCEL_ACTION, t as A2UI_BASIC_CATALOG_ID, u as VercelUiBridge, v as fromVercelToolResult, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-BJobG0i-.js";
3
3
 
4
4
  export { A2UI_BASIC_CATALOG_ID, A2UI_CANCEL_ACTION, A2UI_SUBMIT_ACTION, A2UI_VERSION, CHART_PALETTE, LitRendererBridge, OPENUI_CANCEL_ACTION, OPENUI_SUBMIT_ACTION, VERCEL_INTERACTION_TOOL_NAME, VercelUiBridge, WEBSKILL_STYLES_CSS, WebFormBridge, buildRenderResult, chartToTable, collectValues, ensureStyles, fromA2uiAction, fromOpenUiAction, fromVercelToolResult, interactionToFormModel, renderBlocks, renderMiniChart, renderMiniMarkdown, renderRenderResult, shapeInteractionValue, toA2uiMessages, toOpenUiLang, toVercelToolInvocation };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webskill/sdk",
3
- "version": "0.1.4",
4
- "description": "WebSkill browser/Node agent skill runtime (skills, tools, MCP, governance, UI)",
3
+ "version": "0.2.0",
4
+ "description": "WebSkill \u2014 browser/Node agent skill runtime (skills, tools, MCP, governance, UI)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
@@ -58,17 +58,17 @@
58
58
  "typecheck": "tsc --noEmit"
59
59
  },
60
60
  "dependencies": {
61
- "@modelcontextprotocol/sdk": "^1.29.0",
62
61
  "fflate": "0.8.3",
63
- "oxc-parser": "0.141.0",
64
- "tar": "7.5.21",
65
- "yaml": "^2.9.0",
66
- "zod": "^4.4.3"
62
+ "yaml": "^2.9.0"
67
63
  },
68
64
  "peerDependencies": {
69
65
  "react": ">=19.0.0",
70
66
  "react-dom": ">=19.0.0",
71
- "vue": ">=3.5.0"
67
+ "vue": ">=3.5.0",
68
+ "@modelcontextprotocol/sdk": ">=1.29.0",
69
+ "oxc-parser": ">=0.141.0",
70
+ "tar": ">=7.5.0",
71
+ "zod": ">=4.0.0"
72
72
  },
73
73
  "peerDependenciesMeta": {
74
74
  "react": {
@@ -79,6 +79,18 @@
79
79
  },
80
80
  "vue": {
81
81
  "optional": true
82
+ },
83
+ "@modelcontextprotocol/sdk": {
84
+ "optional": true
85
+ },
86
+ "oxc-parser": {
87
+ "optional": true
88
+ },
89
+ "tar": {
90
+ "optional": true
91
+ },
92
+ "zod": {
93
+ "optional": true
82
94
  }
83
95
  },
84
96
  "devDependencies": {
@@ -93,6 +105,6 @@
93
105
  "@webskill/ui-react": "workspace:*",
94
106
  "@webskill/ui-vue": "workspace:*",
95
107
  "tsdown": "0.22.13",
96
- "typescript": "7.0.2"
108
+ "typescript": "6.0.3"
97
109
  }
98
110
  }