@lingjingai/scriptctl 0.62.0 → 0.62.2

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.
@@ -1208,6 +1208,67 @@ function spanAddresses(doc, actions) {
1208
1208
  });
1209
1209
  }
1210
1210
 
1211
+ // packages/screenplay/dist/references.js
1212
+ function references(doc, address, opts = {}) {
1213
+ const offset = opts.offset ?? 0, limit = opts.limit ?? 20, context = opts.context ?? 3;
1214
+ for (const [name, value, minimum] of [["offset", offset, 0], ["limit", limit, 1], ["context", context, 0]]) {
1215
+ if (!Number.isSafeInteger(value) || value < minimum)
1216
+ throw new Error(`${name} must be an integer >= ${minimum}`);
1217
+ }
1218
+ const node = resolve(doc, address);
1219
+ if (node.t !== "asset" && node.t !== "state")
1220
+ throw new Error("references requires an asset or asset/state address; use read for episodes/scenes/actions");
1221
+ const asset = node.asset;
1222
+ const state2 = node.t === "state" ? node.state.id : null;
1223
+ const names = [.../* @__PURE__ */ new Set([asset.id, asset.name, ...asset.aliases])].filter(Boolean);
1224
+ const hits = [];
1225
+ for (const ep of doc.episodes)
1226
+ for (const scene of ep.scenes) {
1227
+ const bindings = [...scene.location ? [scene.location] : [], ...scene.actors, ...scene.props].filter((ref2) => ref2.id === asset.id && (state2 === null || ref2.states.includes(state2)));
1228
+ if (bindings.length)
1229
+ hits.push({ kind: "scene_binding", scene, matched: bindings.flatMap((ref2) => ref2.states) });
1230
+ for (const action of scene.actions) {
1231
+ if (action.speaker?.id === asset.id && (state2 === null || action.speaker.state === state2)) {
1232
+ hits.push({ kind: "speaker", scene, action, matched: [asset.id] });
1233
+ }
1234
+ if (state2 === null) {
1235
+ const matched = names.filter((name) => action.content.includes(name));
1236
+ if (matched.length)
1237
+ hits.push({ kind: "text_mention", scene, action, matched });
1238
+ }
1239
+ }
1240
+ }
1241
+ const end = offset + limit;
1242
+ return {
1243
+ asset_id: asset.id,
1244
+ state_id: state2,
1245
+ total: hits.length,
1246
+ next_offset: end < hits.length ? end : null,
1247
+ items: hits.slice(offset, end).map(({ kind, scene, action, matched }) => {
1248
+ const index = action ? scene.actions.indexOf(action) : -1;
1249
+ const nearby = action ? scene.actions.slice(Math.max(0, index - context), index + context + 1) : [];
1250
+ const gutter = Math.max(0, ...nearby.map((row) => row.anchor.length));
1251
+ return {
1252
+ kind,
1253
+ address: action?.anchor ?? scene.anchor,
1254
+ scene_address: scene.anchor,
1255
+ episode: scene.ep.no,
1256
+ matched,
1257
+ text: [formatSceneHead(doc, scene), ...nearby.map((row) => (row === action ? "> " : " ") + formatAction(doc, row, gutter))].join("\n")
1258
+ };
1259
+ })
1260
+ };
1261
+ }
1262
+ function formatReferences(result) {
1263
+ return [
1264
+ `${result.asset_id}${result.state_id === null ? "" : "/" + result.state_id} ${result.total} references \xB7 showing ${result.items.length}`,
1265
+ "scene_binding=explicit scene presence; speaker=explicit speaker; text_mention=name/alias mention only (not proof of presence).",
1266
+ ...result.items.map((hit) => `${hit.address} ${hit.kind} ep=${hit.episode}
1267
+ ${hit.text}`),
1268
+ result.next_offset === null ? "end" : `Continue: --offset ${result.next_offset}`
1269
+ ].join("\n\n");
1270
+ }
1271
+
1211
1272
  // packages/screenplay/dist/tools.js
1212
1273
  var NON_ACTOR_KIND = {
1213
1274
  \u65C1\u767D: "system",
@@ -2376,6 +2437,12 @@ var DOCTRINE = `
2376
2437
  - \u65F6\u95F4\u6233\u662F\u5426\u7F3A\u5931\u3001\u5012\u5E8F\u3001\u8D8A\u754C\u6216\u4EA7\u751F\u8D85\u8FC7 15 \u79D2\u7684\u7A7A\u6863\uFF08\u76F8\u90BB\u540C\u503C\u5408\u6CD5\uFF09\u3002
2377
2438
  - \u591A\u72B6\u6001\u4EBA\u7269\u7684\u76F8\u4F3C\u9020\u578B\u5FC5\u987B\u53D6\u5F97\u4EE3\u8868\u6027\u89C6\u9891\u7A97\u53E3\u540E\u518D\u5224\u65AD\uFF0C\u4E0D\u51ED\u540D\u79F0\u76F4\u63A5\u5408\u5E76\u3002
2378
2439
 
2440
+ ## \u5F15\u7528\u5B9A\u4F4D
2441
+
2442
+ - \u7528 \`refs\` \u6309\u8D44\u4EA7\u6216 \`\u8D44\u4EA7/\u9020\u578B\` \u67E5\u5F53\u524D\u5267\u672C\u7684\u5F15\u7528\uFF0C\u6309\u8FD4\u56DE\u7684 offset \u63D0\u793A\u7EED\u8BFB\uFF1B\u518D\u7528 \`read\` \u770B\u547D\u4E2D\u573A/action \u7684\u4E0A\u4E0B\u6587\uFF0C\`span\` \u5B9A\u4F4D\u89C6\u9891\u7A97\u53E3\u3002
2443
+ - \`scene_binding\` \u662F\u573A\u7EA7\u7ED1\u5B9A\uFF0C\`speaker\` \u662F\u8BF4\u8BDD\u5F15\u7528\uFF0C\`text_mention\` \u53EA\u662F\u540D\u5B57/\u522B\u540D/ID \u7684\u6B63\u6587\u63D0\u53CA\uFF1B\u5B83\u4EEC\u90FD\u662F\u5267\u672C\u73B0\u6709\u8BB0\u5F55\uFF0C\u4E0D\u8BC1\u660E\u6807\u7B7E\u6B63\u786E\u6216\u539F\u7247\u5B9E\u9645\u51FA\u573A\u3002\u9020\u578B\u67E5\u8BE2\u53EA\u5339\u914D\u663E\u5F0F\u5F15\u7528\uFF0C\u4E0D\u4ECE\u6B63\u6587\u731C\u9020\u578B\u3002
2444
+ - \`refs\` \u53EA\u8BFB\uFF1B\`ref\` \u624D\u4FEE\u6539\u573A\u666F\u7ED1\u5B9A\u3002\u6539\u4EBA\u7269\u6216\u9020\u578B\u5F15\u7528\u540E\u91CD\u65B0\u67E5\u8BE2\uFF0C\u68C0\u67E5\u4FEE\u6539\u7ED3\u679C\u4E0E\u6B8B\u4F59\u5F15\u7528\u3002\u9010\u96C6\u5BA1\u6838\u53EF\u8DE8\u96C6\u8BFB\u53D6\u4E0A\u4E0B\u6587\uFF0C\u4F46\u4E0D\u56E0\u6B64\u6269\u5927\u672C\u96C6\u4FEE\u6539\u8303\u56F4\u3002
2445
+
2379
2446
  ## \u4FEE\u590D\u89C4\u5219
2380
2447
 
2381
2448
  - \u4EBA\u7269\u8BB0\u5F55\u91CD\u590D \u2192 \u5408\u5E76\u753B\u50CF\u4E0E\u5F15\u7528\uFF0C\u518D\u5220\u6389\u5DF2\u65E0\u5F15\u7528\u7684\u90A3\u4E2A\uFF0C\u4FDD\u7559\u66F4\u7A33\u5B9A/\u5F15\u7528\u66F4\u591A\u7684 ID\u3002
@@ -2444,6 +2511,20 @@ import * as path2 from "node:path";
2444
2511
  import { createTool } from "@mastra/core/tools";
2445
2512
  import { z as z2 } from "zod";
2446
2513
  var ADDR = "\u5730\u5740\uFF1A\u96C6 `3`\u3001\u573A `3-2`\u3001\u5355\u6761 `3-2-5`\u3001\u6B63\u5F0F ID\uFF08`acB4xR8p`/`scnQ7mN2v`\uFF09\u3001\u8D44\u4EA7\u540D\u3001\u6216 `<\u8D44\u4EA7>/<\u72B6\u6001>`";
2514
+ function createRefsTool(doc) {
2515
+ return createTool({
2516
+ id: "refs",
2517
+ description: "\u53EA\u8BFB\u5B9A\u4F4D\u4EBA\u7269/\u573A\u666F/\u9053\u5177\u6216\u5177\u4F53\u9020\u578B\u7684\u5F15\u7528\u3002\u8FD4\u56DE\u573A\u666F\u7ED1\u5B9A\u3001\u8BF4\u8BDD\u4F4D\u7F6E\u3001\u6B63\u6587\u63D0\u53CA\u53CA\u524D\u540E\u6587\uFF1B\u6B63\u6587\u63D0\u53CA\u4E0D\u662F\u51FA\u573A\u8BC1\u636E\u3002\u53EF\u7528\u8FD4\u56DE\u5730\u5740\u7EE7\u7EED read\uFF0C\u6216 span \u5B9A\u4F4D\u539F\u7247\u7A97\u53E3\u3002",
2518
+ inputSchema: z2.object({
2519
+ addr: z2.string().min(1).describe("\u8D44\u4EA7 ID/\u540D\u5B57/\u522B\u540D\uFF0C\u6216 <\u8D44\u4EA7>/<\u9020\u578B>"),
2520
+ offset: z2.number().int().min(0).optional().describe("\u4ECE\u7B2C\u51E0\u6761\u5F15\u7528\u7EED\u8BFB\uFF0C\u4ECE 0 \u5F00\u59CB"),
2521
+ limit: z2.number().int().min(1).max(200).optional().describe("\u672C\u6279\u5F15\u7528\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF1B\u6309\u8FD4\u56DE\u7684 offset \u63D0\u793A\u7EED\u8BFB"),
2522
+ context: z2.number().int().min(0).max(20).optional().describe("\u6B63\u6587\u547D\u4E2D\u524D\u540E\u5404\u51E0\u6761 action\uFF0C\u9ED8\u8BA4 3")
2523
+ }),
2524
+ outputSchema: z2.string(),
2525
+ execute: async ({ addr, ...options }) => formatReferences(references(doc, addr, options))
2526
+ });
2527
+ }
2447
2528
  function frameModelOutput(output) {
2448
2529
  if ("error" in output) return { type: "text", value: output.message };
2449
2530
  const { images, failed, note } = output;
@@ -2517,6 +2598,7 @@ function buildTools(ctx) {
2517
2598
  ...input.limit ? { limit: input.limit } : {}
2518
2599
  })
2519
2600
  });
2601
+ tools.refs = createRefsTool(ctx.doc);
2520
2602
  tools.span = createTool({
2521
2603
  id: "span",
2522
2604
  description: "\u628A\u4E00\u6BB5 action \u6362\u7B97\u6210\u96C6\u5185\u89C6\u9891\u65F6\u95F4\u7A97\u53E3\uFF08\u534A\u5F00\u533A\u95F4\uFF09\uFF0C\u9009 watch/frames \u7684\u7A97\u53E3\u9760\u5B83\u3002",
@@ -2939,6 +3021,7 @@ export {
2939
3021
  SUBJECT_KINDS,
2940
3022
  anchorOf,
2941
3023
  buildTools,
3024
+ createRefsTool,
2942
3025
  cutClip,
2943
3026
  dispatcher,
2944
3027
  episodeTask,