@sjawhar/pi-legion-envoy 0.37.0 → 0.38.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/dist/envoy.js CHANGED
@@ -29650,7 +29650,9 @@ function date4(params) {
29650
29650
  config(en_default());
29651
29651
  // ../contracts/src/dispatch-api.ts
29652
29652
  var DispatchEventSchema = object({
29653
- issue_key: string2(),
29653
+ issue_key: string2().nullable(),
29654
+ artifact_id: string2().nullish(),
29655
+ project: string2().optional(),
29654
29656
  type: string2(),
29655
29657
  actor: object({ kind: string2(), id: string2().optional() }).passthrough(),
29656
29658
  payload: object({}).passthrough()
@@ -29668,7 +29670,7 @@ var ArtifactVersionEventPayloadSchema = object({
29668
29670
  version: object({ number: number2().optional(), summary: string2().nullish() }).optional(),
29669
29671
  diff: string2().optional()
29670
29672
  });
29671
- var AskEventPayloadSchema = object({
29673
+ var askEventPayloadFields = {
29672
29674
  opened_event_id: number2().int().positive(),
29673
29675
  question: string2().optional(),
29674
29676
  options: array(object({ label: string2().optional() })).nullish(),
@@ -29679,6 +29681,23 @@ var AskEventPayloadSchema = object({
29679
29681
  actor: object({ kind: string2().optional(), id: string2().optional() }).passthrough().optional(),
29680
29682
  at: string2().optional()
29681
29683
  }).nullish()
29684
+ };
29685
+ var AskEventPayloadSchema = intersection(object(askEventPayloadFields), object({
29686
+ previous: never().optional(),
29687
+ edited_by: never().optional()
29688
+ }));
29689
+ var AskEditedEventPayloadSchema = object({
29690
+ ...askEventPayloadFields,
29691
+ multiple: boolean2(),
29692
+ urgency: string2(),
29693
+ edited_at: string2().nullish(),
29694
+ previous: object({
29695
+ question: string2(),
29696
+ options: array(object({ label: string2().optional() })),
29697
+ multiple: boolean2(),
29698
+ urgency: string2()
29699
+ }),
29700
+ edited_by: object({ kind: string2(), id: string2() }).passthrough()
29682
29701
  });
29683
29702
  var CommentEventPayloadSchema = object({
29684
29703
  artifact_name: string2().optional(),
@@ -30911,6 +30930,7 @@ var DISPATCH_PAYLOAD_SCHEMAS = {
30911
30930
  "artifact.created": ArtifactCreatedEventPayloadSchema,
30912
30931
  "artifact.version": ArtifactVersionEventPayloadSchema,
30913
30932
  "ask.opened": AskEventPayloadSchema,
30933
+ "ask.edited": AskEditedEventPayloadSchema,
30914
30934
  "ask.answered": AskEventPayloadSchema,
30915
30935
  "ask.resolved": AskEventPayloadSchema,
30916
30936
  "comment.created": CommentEventPayloadSchema,
@@ -30920,6 +30940,18 @@ var DISPATCH_PAYLOAD_SCHEMAS = {
30920
30940
  "message.created": MessageEventPayloadSchema,
30921
30941
  "child.status": ChildStatusEventPayloadSchema
30922
30942
  };
30943
+ var DISPATCH_DOCUMENT_TOPIC_PREFIX = "notifications.dispatch.document.";
30944
+ function dispatchOwner(event, topic) {
30945
+ if (event.issue_key !== null)
30946
+ return event.issue_key;
30947
+ if (topic?.startsWith(DISPATCH_DOCUMENT_TOPIC_PREFIX) === true) {
30948
+ const [project, slug] = topic.slice(DISPATCH_DOCUMENT_TOPIC_PREFIX.length).split(".", 3);
30949
+ if (project !== undefined && project !== "" && slug !== undefined && slug !== "") {
30950
+ return `${project}/${slug}`;
30951
+ }
30952
+ }
30953
+ return event.artifact_id ?? "unknown";
30954
+ }
30923
30955
  function dispatchPayload(event) {
30924
30956
  const schema = DISPATCH_PAYLOAD_SCHEMAS[event.type];
30925
30957
  if (schema === undefined)
@@ -30998,7 +31030,8 @@ function renderInbound(raw, sessionID, subject) {
30998
31030
  }
30999
31031
  askQuestion = dispatchAskQuestion(frame.event);
31000
31032
  dispatchEvent = {
31001
- issue_key: frame.event.issue_key,
31033
+ owner: dispatchOwner(frame.event, subject ?? envelope.topic),
31034
+ ...frame.event.issue_key === null ? frame.event.artifact_id === undefined || frame.event.artifact_id === null ? {} : { artifact_id: frame.event.artifact_id } : { issue_key: frame.event.issue_key },
31002
31035
  type: frame.event.type,
31003
31036
  actor: frame.event.actor,
31004
31037
  payload: dispatchPayload(frame.event)
@@ -31458,6 +31491,23 @@ var nativeIssueKeyPattern = /^[A-Z][A-Z0-9]{1,9}-[0-9]+$/;
31458
31491
  var externalIssueRefPattern = /^([^/\s]+)\/([^/\s#]+)#([1-9][0-9]*)$/;
31459
31492
  var bareIssueNumberPattern = /^[1-9][0-9]*$/;
31460
31493
  var issueFreeTools = new Set(["dispatch_issue", "dispatch_resolve_ask", "dispatch_search"]);
31494
+ async function askResultDetails(client, ask) {
31495
+ if (ask.issue_key !== null) {
31496
+ return {
31497
+ issue: ask.issue_key,
31498
+ topic: dispatchIssueSubject(ask.issue_key, ">"),
31499
+ ask: ask.id
31500
+ };
31501
+ }
31502
+ if (ask.artifact_id === undefined || ask.artifact_id === null) {
31503
+ throw new Error("document ask is missing its artifact ID");
31504
+ }
31505
+ const artifact = await client.getArtifact(ask.artifact_id);
31506
+ return {
31507
+ topic: `notifications.dispatch.document.${artifact.project}.${artifact.slug}.>`,
31508
+ ask: ask.id
31509
+ };
31510
+ }
31461
31511
  function canonicalExternalIssueRef(value) {
31462
31512
  const match = value.trim().match(externalIssueRefPattern);
31463
31513
  return match ? `${canonicalRepo(match[1] ?? "", match[2] ?? "")}#${match[3]}` : value;
@@ -31773,11 +31823,7 @@ async function executeDispatchTool(input) {
31773
31823
  throw new Error("resolved ask is missing its resolution");
31774
31824
  return {
31775
31825
  text: `${kind === "retracted" ? "Retracted" : "Resolved"} ask ${ask.id}: ${ask.resolution.reason}`,
31776
- details: {
31777
- issue: ask.issue_key,
31778
- topic: dispatchIssueSubject(ask.issue_key, ">"),
31779
- ask: ask.id
31780
- }
31826
+ details: await askResultDetails(client, ask)
31781
31827
  };
31782
31828
  }
31783
31829
  case "dispatch_ask": {
@@ -31797,11 +31843,7 @@ async function executeDispatchTool(input) {
31797
31843
  });
31798
31844
  return {
31799
31845
  text: `Opened ask ${ask.id}: ${ask.question}`,
31800
- details: {
31801
- issue: ask.issue_key,
31802
- topic: dispatchIssueSubject(ask.issue_key, ">"),
31803
- ask: ask.id
31804
- }
31846
+ details: await askResultDetails(client, ask)
31805
31847
  };
31806
31848
  }
31807
31849
  case "dispatch_comment": {
@@ -31926,7 +31968,7 @@ Open anchored asks/comments: ${marks.join(", ")}`,
31926
31968
  const askRead = await client.getAsk(issueArguments.ref.id);
31927
31969
  return {
31928
31970
  text: askSummary(askRead),
31929
- details: { issue: askRead.ask.issue_key }
31971
+ details: { issue: issueArguments.ref.issue }
31930
31972
  };
31931
31973
  }
31932
31974
  if (issueArguments.ref?.kind === "comment") {
package/dist/legion.js CHANGED
@@ -29648,7 +29648,9 @@ function date4(params) {
29648
29648
  config(en_default());
29649
29649
  // ../contracts/src/dispatch-api.ts
29650
29650
  var DispatchEventSchema = object({
29651
- issue_key: string2(),
29651
+ issue_key: string2().nullable(),
29652
+ artifact_id: string2().nullish(),
29653
+ project: string2().optional(),
29652
29654
  type: string2(),
29653
29655
  actor: object({ kind: string2(), id: string2().optional() }).passthrough(),
29654
29656
  payload: object({}).passthrough()
@@ -29666,7 +29668,7 @@ var ArtifactVersionEventPayloadSchema = object({
29666
29668
  version: object({ number: number2().optional(), summary: string2().nullish() }).optional(),
29667
29669
  diff: string2().optional()
29668
29670
  });
29669
- var AskEventPayloadSchema = object({
29671
+ var askEventPayloadFields = {
29670
29672
  opened_event_id: number2().int().positive(),
29671
29673
  question: string2().optional(),
29672
29674
  options: array(object({ label: string2().optional() })).nullish(),
@@ -29677,6 +29679,23 @@ var AskEventPayloadSchema = object({
29677
29679
  actor: object({ kind: string2().optional(), id: string2().optional() }).passthrough().optional(),
29678
29680
  at: string2().optional()
29679
29681
  }).nullish()
29682
+ };
29683
+ var AskEventPayloadSchema = intersection(object(askEventPayloadFields), object({
29684
+ previous: never().optional(),
29685
+ edited_by: never().optional()
29686
+ }));
29687
+ var AskEditedEventPayloadSchema = object({
29688
+ ...askEventPayloadFields,
29689
+ multiple: boolean2(),
29690
+ urgency: string2(),
29691
+ edited_at: string2().nullish(),
29692
+ previous: object({
29693
+ question: string2(),
29694
+ options: array(object({ label: string2().optional() })),
29695
+ multiple: boolean2(),
29696
+ urgency: string2()
29697
+ }),
29698
+ edited_by: object({ kind: string2(), id: string2() }).passthrough()
29680
29699
  });
29681
29700
  var CommentEventPayloadSchema = object({
29682
29701
  artifact_name: string2().optional(),
@@ -31357,6 +31376,7 @@ var DISPATCH_PAYLOAD_SCHEMAS = {
31357
31376
  "artifact.created": ArtifactCreatedEventPayloadSchema,
31358
31377
  "artifact.version": ArtifactVersionEventPayloadSchema,
31359
31378
  "ask.opened": AskEventPayloadSchema,
31379
+ "ask.edited": AskEditedEventPayloadSchema,
31360
31380
  "ask.answered": AskEventPayloadSchema,
31361
31381
  "ask.resolved": AskEventPayloadSchema,
31362
31382
  "comment.created": CommentEventPayloadSchema,
@@ -31366,6 +31386,18 @@ var DISPATCH_PAYLOAD_SCHEMAS = {
31366
31386
  "message.created": MessageEventPayloadSchema,
31367
31387
  "child.status": ChildStatusEventPayloadSchema
31368
31388
  };
31389
+ var DISPATCH_DOCUMENT_TOPIC_PREFIX = "notifications.dispatch.document.";
31390
+ function dispatchOwner(event, topic) {
31391
+ if (event.issue_key !== null)
31392
+ return event.issue_key;
31393
+ if (topic?.startsWith(DISPATCH_DOCUMENT_TOPIC_PREFIX) === true) {
31394
+ const [project, slug] = topic.slice(DISPATCH_DOCUMENT_TOPIC_PREFIX.length).split(".", 3);
31395
+ if (project !== undefined && project !== "" && slug !== undefined && slug !== "") {
31396
+ return `${project}/${slug}`;
31397
+ }
31398
+ }
31399
+ return event.artifact_id ?? "unknown";
31400
+ }
31369
31401
  function dispatchPayload(event) {
31370
31402
  const schema = DISPATCH_PAYLOAD_SCHEMAS[event.type];
31371
31403
  if (schema === undefined)
@@ -31444,7 +31476,8 @@ function renderInbound(raw, sessionID, subject) {
31444
31476
  }
31445
31477
  askQuestion = dispatchAskQuestion(frame.event);
31446
31478
  dispatchEvent = {
31447
- issue_key: frame.event.issue_key,
31479
+ owner: dispatchOwner(frame.event, subject ?? envelope.topic),
31480
+ ...frame.event.issue_key === null ? frame.event.artifact_id === undefined || frame.event.artifact_id === null ? {} : { artifact_id: frame.event.artifact_id } : { issue_key: frame.event.issue_key },
31448
31481
  type: frame.event.type,
31449
31482
  actor: frame.event.actor,
31450
31483
  payload: dispatchPayload(frame.event)
@@ -31897,6 +31930,23 @@ var nativeIssueKeyPattern = /^[A-Z][A-Z0-9]{1,9}-[0-9]+$/;
31897
31930
  var externalIssueRefPattern = /^([^/\s]+)\/([^/\s#]+)#([1-9][0-9]*)$/;
31898
31931
  var bareIssueNumberPattern = /^[1-9][0-9]*$/;
31899
31932
  var issueFreeTools = new Set(["dispatch_issue", "dispatch_resolve_ask", "dispatch_search"]);
31933
+ async function askResultDetails(client, ask) {
31934
+ if (ask.issue_key !== null) {
31935
+ return {
31936
+ issue: ask.issue_key,
31937
+ topic: dispatchIssueSubject(ask.issue_key, ">"),
31938
+ ask: ask.id
31939
+ };
31940
+ }
31941
+ if (ask.artifact_id === undefined || ask.artifact_id === null) {
31942
+ throw new Error("document ask is missing its artifact ID");
31943
+ }
31944
+ const artifact = await client.getArtifact(ask.artifact_id);
31945
+ return {
31946
+ topic: `notifications.dispatch.document.${artifact.project}.${artifact.slug}.>`,
31947
+ ask: ask.id
31948
+ };
31949
+ }
31900
31950
  function canonicalExternalIssueRef(value) {
31901
31951
  const match = value.trim().match(externalIssueRefPattern);
31902
31952
  return match ? `${canonicalRepo(match[1] ?? "", match[2] ?? "")}#${match[3]}` : value;
@@ -32212,11 +32262,7 @@ async function executeDispatchTool(input) {
32212
32262
  throw new Error("resolved ask is missing its resolution");
32213
32263
  return {
32214
32264
  text: `${kind === "retracted" ? "Retracted" : "Resolved"} ask ${ask.id}: ${ask.resolution.reason}`,
32215
- details: {
32216
- issue: ask.issue_key,
32217
- topic: dispatchIssueSubject(ask.issue_key, ">"),
32218
- ask: ask.id
32219
- }
32265
+ details: await askResultDetails(client, ask)
32220
32266
  };
32221
32267
  }
32222
32268
  case "dispatch_ask": {
@@ -32236,11 +32282,7 @@ async function executeDispatchTool(input) {
32236
32282
  });
32237
32283
  return {
32238
32284
  text: `Opened ask ${ask.id}: ${ask.question}`,
32239
- details: {
32240
- issue: ask.issue_key,
32241
- topic: dispatchIssueSubject(ask.issue_key, ">"),
32242
- ask: ask.id
32243
- }
32285
+ details: await askResultDetails(client, ask)
32244
32286
  };
32245
32287
  }
32246
32288
  case "dispatch_comment": {
@@ -32365,7 +32407,7 @@ Open anchored asks/comments: ${marks.join(", ")}`,
32365
32407
  const askRead = await client.getAsk(issueArguments.ref.id);
32366
32408
  return {
32367
32409
  text: askSummary(askRead),
32368
- details: { issue: askRead.ask.issue_key }
32410
+ details: { issue: issueArguments.ref.issue }
32369
32411
  };
32370
32412
  }
32371
32413
  if (issueArguments.ref?.kind === "comment") {
@@ -141,11 +141,16 @@ type EditOp = {
141
141
  };
142
142
  ```
143
143
 
144
- Target edits by quote: `replace` requires `find` and `with`; `delete` requires `find`; `insert`
145
- requires `markdown` and exactly one of `after` or `before`. An insert anchor is a quote,
146
- `"start"`, `"end"`, or `"heading:Title"`. Use zero-based `occurrence` for a repeated `find`.
147
- When a decision lands, pass `summary` to name the resulting version. Never paste progress into a
148
- message.
144
+ Target `replace` and `delete` by the document's plain text: inline-code and link text match
145
+ without Markdown syntax, and a table-cell anchor is its cell text. `replace` requires `find` and
146
+ `with`; `delete` requires `find`; `insert` requires `markdown` and exactly one of `after` or
147
+ `before`. An insert anchor is a quote, `"start"`, `"end"`, or `"heading:Title"`. Every insert
148
+ creates a sibling block before or after the quote or heading's enclosing document block; `"start"`
149
+ and `"end"` select the document edges. At a table-cell quote, pipe-table body-row fragments extend
150
+ that table before or after the matched row; omit table header and delimiter rows, and do not exceed
151
+ the table width. Use `replace` for inline continuation. Use zero-based `occurrence` for a repeated
152
+ target. When a decision lands, pass `summary` to name the resulting version. Never paste progress
153
+ into a message.
149
154
 
150
155
  ## Comments and suggestions
151
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-legion-envoy",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "type": "module",
5
5
  "omp": {
6
6
  "extensions": [