@perstack/core 0.0.32 → 0.0.34

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/src/index.js CHANGED
@@ -136,16 +136,6 @@ function createCompleteRunEvent(jobId, runId, expertKey, checkpoint, output, sta
136
136
  usage: createEmptyUsage()
137
137
  };
138
138
  }
139
- function createStreamingTextEvent(jobId, runId, text) {
140
- return {
141
- type: "streamingText",
142
- id: createId(),
143
- timestamp: Date.now(),
144
- jobId,
145
- runId,
146
- text
147
- };
148
- }
149
139
  function createCallToolsEvent(jobId, runId, expertKey, stepNumber, toolCalls, _checkpoint) {
150
140
  const expertMessage = {
151
141
  id: createId(),
@@ -506,7 +496,216 @@ var messagePartSchema = z.discriminatedUnion("type", [
506
496
  thinkingPartSchema
507
497
  ]);
508
498
 
509
- // src/schemas/message.ts
499
+ // src/schemas/activity.ts
500
+ var baseActivitySchema = z.object({
501
+ id: z.string(),
502
+ expertKey: z.string(),
503
+ runId: z.string(),
504
+ previousActivityId: z.string().optional(),
505
+ delegatedBy: z.object({
506
+ expertKey: z.string(),
507
+ runId: z.string()
508
+ }).optional(),
509
+ reasoning: z.string().optional()
510
+ });
511
+ var queryActivitySchema = baseActivitySchema.extend({
512
+ type: z.literal("query"),
513
+ text: z.string()
514
+ });
515
+ var retryActivitySchema = baseActivitySchema.extend({
516
+ type: z.literal("retry"),
517
+ error: z.string(),
518
+ message: z.string()
519
+ });
520
+ var completeActivitySchema = baseActivitySchema.extend({
521
+ type: z.literal("complete"),
522
+ text: z.string()
523
+ });
524
+ var errorActivitySchema = baseActivitySchema.extend({
525
+ type: z.literal("error"),
526
+ error: z.string().optional(),
527
+ errorName: z.string().optional(),
528
+ isRetryable: z.boolean().optional()
529
+ });
530
+ var attemptCompletionActivitySchema = baseActivitySchema.extend({
531
+ type: z.literal("attemptCompletion"),
532
+ remainingTodos: z.array(z.object({ id: z.number(), title: z.string(), completed: z.boolean() })).optional(),
533
+ error: z.string().optional()
534
+ });
535
+ var todoActivitySchema = baseActivitySchema.extend({
536
+ type: z.literal("todo"),
537
+ newTodos: z.array(z.string()).optional(),
538
+ completedTodos: z.array(z.number()).optional(),
539
+ todos: z.array(z.object({ id: z.number(), title: z.string(), completed: z.boolean() })),
540
+ error: z.string().optional()
541
+ });
542
+ var clearTodoActivitySchema = baseActivitySchema.extend({
543
+ type: z.literal("clearTodo"),
544
+ error: z.string().optional()
545
+ });
546
+ var readImageFileActivitySchema = baseActivitySchema.extend({
547
+ type: z.literal("readImageFile"),
548
+ path: z.string(),
549
+ mimeType: z.string().optional(),
550
+ size: z.number().optional(),
551
+ error: z.string().optional()
552
+ });
553
+ var readPdfFileActivitySchema = baseActivitySchema.extend({
554
+ type: z.literal("readPdfFile"),
555
+ path: z.string(),
556
+ mimeType: z.string().optional(),
557
+ size: z.number().optional(),
558
+ error: z.string().optional()
559
+ });
560
+ var readTextFileActivitySchema = baseActivitySchema.extend({
561
+ type: z.literal("readTextFile"),
562
+ path: z.string(),
563
+ content: z.string().optional(),
564
+ from: z.number().optional(),
565
+ to: z.number().optional(),
566
+ error: z.string().optional()
567
+ });
568
+ var editTextFileActivitySchema = baseActivitySchema.extend({
569
+ type: z.literal("editTextFile"),
570
+ path: z.string(),
571
+ newText: z.string(),
572
+ oldText: z.string(),
573
+ error: z.string().optional()
574
+ });
575
+ var appendTextFileActivitySchema = baseActivitySchema.extend({
576
+ type: z.literal("appendTextFile"),
577
+ path: z.string(),
578
+ text: z.string(),
579
+ error: z.string().optional()
580
+ });
581
+ var writeTextFileActivitySchema = baseActivitySchema.extend({
582
+ type: z.literal("writeTextFile"),
583
+ path: z.string(),
584
+ text: z.string(),
585
+ error: z.string().optional()
586
+ });
587
+ var deleteFileActivitySchema = baseActivitySchema.extend({
588
+ type: z.literal("deleteFile"),
589
+ path: z.string(),
590
+ error: z.string().optional()
591
+ });
592
+ var deleteDirectoryActivitySchema = baseActivitySchema.extend({
593
+ type: z.literal("deleteDirectory"),
594
+ path: z.string(),
595
+ recursive: z.boolean().optional(),
596
+ error: z.string().optional()
597
+ });
598
+ var moveFileActivitySchema = baseActivitySchema.extend({
599
+ type: z.literal("moveFile"),
600
+ source: z.string(),
601
+ destination: z.string(),
602
+ error: z.string().optional()
603
+ });
604
+ var getFileInfoActivitySchema = baseActivitySchema.extend({
605
+ type: z.literal("getFileInfo"),
606
+ path: z.string(),
607
+ info: z.object({
608
+ exists: z.boolean(),
609
+ name: z.string(),
610
+ directory: z.string(),
611
+ extension: z.string().nullable(),
612
+ type: z.enum(["file", "directory"]),
613
+ mimeType: z.string().nullable(),
614
+ size: z.number(),
615
+ sizeFormatted: z.string(),
616
+ created: z.string(),
617
+ modified: z.string(),
618
+ accessed: z.string()
619
+ }).optional(),
620
+ error: z.string().optional()
621
+ });
622
+ var createDirectoryActivitySchema = baseActivitySchema.extend({
623
+ type: z.literal("createDirectory"),
624
+ path: z.string(),
625
+ error: z.string().optional()
626
+ });
627
+ var listDirectoryActivitySchema = baseActivitySchema.extend({
628
+ type: z.literal("listDirectory"),
629
+ path: z.string(),
630
+ items: z.array(
631
+ z.object({
632
+ name: z.string(),
633
+ path: z.string(),
634
+ type: z.enum(["file", "directory"]),
635
+ size: z.number(),
636
+ modified: z.string()
637
+ })
638
+ ).optional(),
639
+ error: z.string().optional()
640
+ });
641
+ var execActivitySchema = baseActivitySchema.extend({
642
+ type: z.literal("exec"),
643
+ command: z.string(),
644
+ args: z.array(z.string()),
645
+ cwd: z.string(),
646
+ output: z.string().optional(),
647
+ error: z.string().optional(),
648
+ stdout: z.string().optional(),
649
+ stderr: z.string().optional()
650
+ });
651
+ var delegateActivitySchema = baseActivitySchema.extend({
652
+ type: z.literal("delegate"),
653
+ delegateExpertKey: z.string(),
654
+ query: z.string()
655
+ });
656
+ var delegationCompleteActivitySchema = baseActivitySchema.extend({
657
+ type: z.literal("delegationComplete"),
658
+ count: z.number()
659
+ });
660
+ var interactiveToolActivitySchema = baseActivitySchema.extend({
661
+ type: z.literal("interactiveTool"),
662
+ skillName: z.string(),
663
+ toolName: z.string(),
664
+ args: z.record(z.string(), z.unknown())
665
+ });
666
+ var generalToolActivitySchema = baseActivitySchema.extend({
667
+ type: z.literal("generalTool"),
668
+ skillName: z.string(),
669
+ toolName: z.string(),
670
+ args: z.record(z.string(), z.unknown()),
671
+ result: z.array(messagePartSchema).optional(),
672
+ error: z.string().optional()
673
+ });
674
+ var activitySchema = z.discriminatedUnion("type", [
675
+ queryActivitySchema,
676
+ retryActivitySchema,
677
+ completeActivitySchema,
678
+ errorActivitySchema,
679
+ attemptCompletionActivitySchema,
680
+ todoActivitySchema,
681
+ clearTodoActivitySchema,
682
+ readImageFileActivitySchema,
683
+ readPdfFileActivitySchema,
684
+ readTextFileActivitySchema,
685
+ editTextFileActivitySchema,
686
+ appendTextFileActivitySchema,
687
+ writeTextFileActivitySchema,
688
+ deleteFileActivitySchema,
689
+ deleteDirectoryActivitySchema,
690
+ moveFileActivitySchema,
691
+ getFileInfoActivitySchema,
692
+ createDirectoryActivitySchema,
693
+ listDirectoryActivitySchema,
694
+ execActivitySchema,
695
+ delegateActivitySchema,
696
+ delegationCompleteActivitySchema,
697
+ interactiveToolActivitySchema,
698
+ generalToolActivitySchema
699
+ ]);
700
+ var parallelActivitiesGroupSchema = z.object({
701
+ type: z.literal("parallelGroup"),
702
+ id: z.string(),
703
+ expertKey: z.string(),
704
+ runId: z.string(),
705
+ reasoning: z.string().optional(),
706
+ activities: z.array(activitySchema)
707
+ });
708
+ var activityOrGroupSchema = z.union([activitySchema, parallelActivitiesGroupSchema]);
510
709
  var baseMessageSchema = z.object({
511
710
  id: z.string()
512
711
  });
@@ -608,7 +807,8 @@ var checkpointSchema = z.object({
608
807
  }),
609
808
  toolCallId: z.string(),
610
809
  toolName: z.string(),
611
- checkpointId: z.string()
810
+ checkpointId: z.string(),
811
+ runId: z.string()
612
812
  }).optional(),
613
813
  usage: usageSchema,
614
814
  contextWindow: z.number().optional(),
@@ -1166,7 +1366,12 @@ var commandOptionsSchema = z.object({
1166
1366
  resumeFrom: z.string().optional(),
1167
1367
  interactiveToolCallResult: z.boolean().optional(),
1168
1368
  runtime: runtimeNameSchema.optional(),
1169
- workspace: z.string().optional()
1369
+ workspace: z.string().optional(),
1370
+ volume: z.array(z.string()).optional().transform((value) => value && value.length > 0 ? value : void 0),
1371
+ filter: z.string().optional().transform((value) => {
1372
+ if (value === void 0) return void 0;
1373
+ return value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
1374
+ }).pipe(z.array(z.string()).optional())
1170
1375
  });
1171
1376
  var runCommandInputSchema = z.object({
1172
1377
  expertKey: z.string(),
@@ -1274,17 +1479,30 @@ function createEvent(type) {
1274
1479
  };
1275
1480
  };
1276
1481
  }
1482
+ function createStreamingEvent(type, setting, checkpoint, data) {
1483
+ return {
1484
+ type,
1485
+ id: createId(),
1486
+ expertKey: checkpoint.expert.key,
1487
+ timestamp: Date.now(),
1488
+ jobId: setting.jobId,
1489
+ runId: setting.runId,
1490
+ stepNumber: checkpoint.stepNumber,
1491
+ ...data
1492
+ };
1493
+ }
1277
1494
  var startRun = createEvent("startRun");
1495
+ var resumeFromStop = createEvent("resumeFromStop");
1496
+ var proceedToInteractiveTools = createEvent("proceedToInteractiveTools");
1278
1497
  var startGeneration = createEvent("startGeneration");
1279
1498
  var retry = createEvent("retry");
1280
1499
  var callTools = createEvent("callTools");
1281
- var callInteractiveTool = createEvent("callInteractiveTool");
1282
- var callDelegate = createEvent("callDelegate");
1500
+ var finishMcpTools = createEvent("finishMcpTools");
1501
+ var skipDelegates = createEvent("skipDelegates");
1283
1502
  var resolveToolResults = createEvent("resolveToolResults");
1284
1503
  var attemptCompletion = createEvent("attemptCompletion");
1285
1504
  var finishToolCall = createEvent("finishToolCall");
1286
1505
  var resumeToolCalls = createEvent("resumeToolCalls");
1287
- var finishAllToolCalls = createEvent("finishAllToolCalls");
1288
1506
  var completeRun = createEvent("completeRun");
1289
1507
  var stopRunByInteractiveTool = createEvent("stopRunByInteractiveTool");
1290
1508
  var stopRunByDelegate = createEvent("stopRunByDelegate");
@@ -1301,6 +1519,50 @@ function createRuntimeEvent(type, jobId, runId, data) {
1301
1519
  ...data
1302
1520
  };
1303
1521
  }
1522
+ var EXPERT_STATE_EVENT_TYPES = /* @__PURE__ */ new Set([
1523
+ "startRun",
1524
+ "resumeFromStop",
1525
+ "proceedToInteractiveTools",
1526
+ "startGeneration",
1527
+ "retry",
1528
+ "callTools",
1529
+ "finishMcpTools",
1530
+ "skipDelegates",
1531
+ "resolveToolResults",
1532
+ "attemptCompletion",
1533
+ "finishToolCall",
1534
+ "resumeToolCalls",
1535
+ "continueToNextStep",
1536
+ "stopRunByInteractiveTool",
1537
+ "stopRunByDelegate",
1538
+ "stopRunByExceededMaxSteps",
1539
+ "stopRunByError",
1540
+ "completeRun"
1541
+ ]);
1542
+ var STREAMING_EVENT_TYPES = /* @__PURE__ */ new Set([
1543
+ "startStreamingReasoning",
1544
+ "streamReasoning",
1545
+ "completeStreamingReasoning",
1546
+ "startStreamingRunResult",
1547
+ "streamRunResult",
1548
+ "completeStreamingRunResult"
1549
+ ]);
1550
+ var RUNTIME_EVENT_TYPES = /* @__PURE__ */ new Set([
1551
+ "initializeRuntime",
1552
+ "skillStarting",
1553
+ "skillConnected",
1554
+ "skillStderr",
1555
+ "skillDisconnected",
1556
+ "dockerBuildProgress",
1557
+ "dockerContainerStatus",
1558
+ "proxyAccess"
1559
+ ]);
1560
+ function isValidEventType(type) {
1561
+ return EXPERT_STATE_EVENT_TYPES.has(type) || STREAMING_EVENT_TYPES.has(type);
1562
+ }
1563
+ function isValidRuntimeEventType(type) {
1564
+ return RUNTIME_EVENT_TYPES.has(type);
1565
+ }
1304
1566
  var stepSchema = z.object({
1305
1567
  stepNumber: z.number(),
1306
1568
  inputMessages: z.array(z.union([instructionMessageSchema, userMessageSchema, toolMessageSchema])).optional(),
@@ -1314,6 +1576,440 @@ var stepSchema = z.object({
1314
1576
  finishedAt: z.number().optional()
1315
1577
  });
1316
1578
 
1579
+ // src/utils/activity.ts
1580
+ var BASE_SKILL_PREFIX = "@perstack/base";
1581
+ function extractReasoning(newMessages) {
1582
+ const thinkingParts = [];
1583
+ for (const message of newMessages) {
1584
+ for (const content of message.contents) {
1585
+ if (content.type === "thinkingPart") {
1586
+ thinkingParts.push(content);
1587
+ }
1588
+ }
1589
+ }
1590
+ if (thinkingParts.length === 0) return void 0;
1591
+ return thinkingParts.map((p) => p.thinking).join("\n\n");
1592
+ }
1593
+ function wrapInGroupIfParallel(activities, reasoning, expertKey, runId, stepNumber) {
1594
+ if (activities.length <= 1) {
1595
+ return activities;
1596
+ }
1597
+ const activitiesWithoutReasoning = activities.map((a) => {
1598
+ const { reasoning: _, ...rest } = a;
1599
+ return rest;
1600
+ });
1601
+ const group = {
1602
+ type: "parallelGroup",
1603
+ id: `parallel-${runId}-step${stepNumber}`,
1604
+ expertKey,
1605
+ runId,
1606
+ reasoning,
1607
+ activities: activitiesWithoutReasoning
1608
+ };
1609
+ return [group];
1610
+ }
1611
+ function getActivities(params) {
1612
+ const { checkpoint, step } = params;
1613
+ const { status, delegateTo, runId, stepNumber } = checkpoint;
1614
+ const expertKey = checkpoint.expert.key;
1615
+ const reasoning = extractReasoning(step.newMessages);
1616
+ if (status === "completed") {
1617
+ return [createCompleteActivity(step.newMessages, reasoning)];
1618
+ }
1619
+ if (status === "stoppedByError") {
1620
+ return [createErrorActivity(checkpoint, reasoning)];
1621
+ }
1622
+ if (status === "stoppedByDelegate") {
1623
+ if (!delegateTo || delegateTo.length === 0) {
1624
+ return [
1625
+ createRetryActivity(
1626
+ step.newMessages,
1627
+ reasoning,
1628
+ "Delegate status but no delegation targets"
1629
+ )
1630
+ ];
1631
+ }
1632
+ const activities2 = delegateTo.map((d) => createDelegateActivity(d, reasoning));
1633
+ return wrapInGroupIfParallel(activities2, reasoning, expertKey, runId, stepNumber);
1634
+ }
1635
+ if (status === "stoppedByInteractiveTool") {
1636
+ const toolCalls2 = step.toolCalls ?? [];
1637
+ if (toolCalls2.length === 0) {
1638
+ return [createRetryActivity(step.newMessages, reasoning)];
1639
+ }
1640
+ const activities2 = toolCalls2.map(
1641
+ (tc) => createInteractiveToolActivity(tc.skillName, tc.toolName, tc, reasoning)
1642
+ );
1643
+ return wrapInGroupIfParallel(activities2, reasoning, expertKey, runId, stepNumber);
1644
+ }
1645
+ const toolCalls = step.toolCalls ?? [];
1646
+ const toolResults = step.toolResults ?? [];
1647
+ if (toolCalls.length === 0) {
1648
+ return [createRetryActivity(step.newMessages, reasoning)];
1649
+ }
1650
+ const activities = [];
1651
+ for (const toolCall of toolCalls) {
1652
+ const toolResult = toolResults.find((tr) => tr.id === toolCall.id);
1653
+ if (!toolResult) {
1654
+ continue;
1655
+ }
1656
+ const { skillName, toolName } = toolCall;
1657
+ if (skillName.startsWith(BASE_SKILL_PREFIX)) {
1658
+ activities.push(createBaseToolActivity(toolName, toolCall, toolResult, reasoning));
1659
+ } else {
1660
+ activities.push(
1661
+ createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning)
1662
+ );
1663
+ }
1664
+ }
1665
+ if (activities.length === 0) {
1666
+ return [createRetryActivity(step.newMessages, reasoning)];
1667
+ }
1668
+ return wrapInGroupIfParallel(activities, reasoning, expertKey, runId, stepNumber);
1669
+ }
1670
+ function createCompleteActivity(newMessages, reasoning) {
1671
+ const lastExpertMessage = [...newMessages].reverse().find((m) => m.type === "expertMessage");
1672
+ const textPart = lastExpertMessage?.contents.find((c) => c.type === "textPart");
1673
+ return {
1674
+ type: "complete",
1675
+ id: "",
1676
+ expertKey: "",
1677
+ runId: "",
1678
+ reasoning,
1679
+ text: textPart?.text ?? ""
1680
+ };
1681
+ }
1682
+ function createDelegateActivity(delegate, reasoning) {
1683
+ return {
1684
+ type: "delegate",
1685
+ id: "",
1686
+ expertKey: "",
1687
+ runId: "",
1688
+ reasoning,
1689
+ delegateExpertKey: delegate.expert.key,
1690
+ query: delegate.query
1691
+ };
1692
+ }
1693
+ function createInteractiveToolActivity(skillName, toolName, toolCall, reasoning) {
1694
+ return {
1695
+ type: "interactiveTool",
1696
+ id: "",
1697
+ expertKey: "",
1698
+ runId: "",
1699
+ reasoning,
1700
+ skillName,
1701
+ toolName,
1702
+ args: toolCall.args
1703
+ };
1704
+ }
1705
+ function createRetryActivity(newMessages, reasoning, customError) {
1706
+ const lastMessage = newMessages[newMessages.length - 1];
1707
+ const textPart = lastMessage?.contents.find((c) => c.type === "textPart");
1708
+ return {
1709
+ type: "retry",
1710
+ id: "",
1711
+ expertKey: "",
1712
+ runId: "",
1713
+ reasoning,
1714
+ error: customError ?? "No tool call or result found",
1715
+ message: textPart?.text ?? ""
1716
+ };
1717
+ }
1718
+ function createErrorActivity(checkpoint, reasoning) {
1719
+ const error = checkpoint.error;
1720
+ return {
1721
+ type: "error",
1722
+ id: "",
1723
+ expertKey: "",
1724
+ runId: "",
1725
+ reasoning,
1726
+ error: error?.message ?? "Unknown error",
1727
+ errorName: error?.name,
1728
+ isRetryable: error?.isRetryable
1729
+ };
1730
+ }
1731
+ function createBaseToolActivity(toolName, toolCall, toolResult, reasoning) {
1732
+ const args = toolCall.args;
1733
+ const resultContents = toolResult.result;
1734
+ const errorText = getErrorFromResult(resultContents);
1735
+ const baseFields = { id: "", expertKey: "", runId: "", reasoning };
1736
+ switch (toolName) {
1737
+ case "attemptCompletion": {
1738
+ const remainingTodos = parseRemainingTodosFromResult(resultContents);
1739
+ return {
1740
+ type: "attemptCompletion",
1741
+ ...baseFields,
1742
+ remainingTodos,
1743
+ error: errorText
1744
+ };
1745
+ }
1746
+ case "todo": {
1747
+ const todos = parseTodosFromResult(resultContents);
1748
+ return {
1749
+ type: "todo",
1750
+ ...baseFields,
1751
+ newTodos: Array.isArray(args["newTodos"]) ? args["newTodos"].map(String) : void 0,
1752
+ completedTodos: Array.isArray(args["completedTodos"]) ? args["completedTodos"].map(Number) : void 0,
1753
+ todos,
1754
+ error: errorText
1755
+ };
1756
+ }
1757
+ case "clearTodo":
1758
+ return {
1759
+ type: "clearTodo",
1760
+ ...baseFields,
1761
+ error: errorText
1762
+ };
1763
+ case "readImageFile":
1764
+ return {
1765
+ type: "readImageFile",
1766
+ ...baseFields,
1767
+ path: String(args["path"] ?? ""),
1768
+ mimeType: parseStringField(resultContents, "mimeType"),
1769
+ size: parseNumberField(resultContents, "size"),
1770
+ error: errorText
1771
+ };
1772
+ case "readPdfFile":
1773
+ return {
1774
+ type: "readPdfFile",
1775
+ ...baseFields,
1776
+ path: String(args["path"] ?? ""),
1777
+ mimeType: parseStringField(resultContents, "mimeType"),
1778
+ size: parseNumberField(resultContents, "size"),
1779
+ error: errorText
1780
+ };
1781
+ case "readTextFile":
1782
+ return {
1783
+ type: "readTextFile",
1784
+ ...baseFields,
1785
+ path: String(args["path"] ?? ""),
1786
+ content: parseStringField(resultContents, "content"),
1787
+ from: typeof args["from"] === "number" ? args["from"] : void 0,
1788
+ to: typeof args["to"] === "number" ? args["to"] : void 0,
1789
+ error: errorText
1790
+ };
1791
+ case "editTextFile":
1792
+ return {
1793
+ type: "editTextFile",
1794
+ ...baseFields,
1795
+ path: String(args["path"] ?? ""),
1796
+ newText: String(args["newText"] ?? ""),
1797
+ oldText: String(args["oldText"] ?? ""),
1798
+ error: errorText
1799
+ };
1800
+ case "appendTextFile":
1801
+ return {
1802
+ type: "appendTextFile",
1803
+ ...baseFields,
1804
+ path: String(args["path"] ?? ""),
1805
+ text: String(args["text"] ?? ""),
1806
+ error: errorText
1807
+ };
1808
+ case "writeTextFile":
1809
+ return {
1810
+ type: "writeTextFile",
1811
+ ...baseFields,
1812
+ path: String(args["path"] ?? ""),
1813
+ text: String(args["text"] ?? ""),
1814
+ error: errorText
1815
+ };
1816
+ case "deleteFile":
1817
+ return {
1818
+ type: "deleteFile",
1819
+ ...baseFields,
1820
+ path: String(args["path"] ?? ""),
1821
+ error: errorText
1822
+ };
1823
+ case "deleteDirectory":
1824
+ return {
1825
+ type: "deleteDirectory",
1826
+ ...baseFields,
1827
+ path: String(args["path"] ?? ""),
1828
+ recursive: typeof args["recursive"] === "boolean" ? args["recursive"] : void 0,
1829
+ error: errorText
1830
+ };
1831
+ case "moveFile":
1832
+ return {
1833
+ type: "moveFile",
1834
+ ...baseFields,
1835
+ source: String(args["source"] ?? ""),
1836
+ destination: String(args["destination"] ?? ""),
1837
+ error: errorText
1838
+ };
1839
+ case "getFileInfo":
1840
+ return {
1841
+ type: "getFileInfo",
1842
+ ...baseFields,
1843
+ path: String(args["path"] ?? ""),
1844
+ info: parseFileInfoFromResult(resultContents),
1845
+ error: errorText
1846
+ };
1847
+ case "createDirectory":
1848
+ return {
1849
+ type: "createDirectory",
1850
+ ...baseFields,
1851
+ path: String(args["path"] ?? ""),
1852
+ error: errorText
1853
+ };
1854
+ case "listDirectory":
1855
+ return {
1856
+ type: "listDirectory",
1857
+ ...baseFields,
1858
+ path: String(args["path"] ?? ""),
1859
+ items: parseListDirectoryFromResult(resultContents),
1860
+ error: errorText
1861
+ };
1862
+ case "exec":
1863
+ return {
1864
+ type: "exec",
1865
+ ...baseFields,
1866
+ command: String(args["command"] ?? ""),
1867
+ args: Array.isArray(args["args"]) ? args["args"].map(String) : [],
1868
+ cwd: String(args["cwd"] ?? ""),
1869
+ output: parseStringField(resultContents, "output"),
1870
+ error: errorText,
1871
+ stdout: parseStringField(resultContents, "stdout"),
1872
+ stderr: parseStringField(resultContents, "stderr")
1873
+ };
1874
+ default:
1875
+ return createGeneralToolActivity(
1876
+ toolCall.skillName,
1877
+ toolName,
1878
+ toolCall,
1879
+ toolResult,
1880
+ reasoning
1881
+ );
1882
+ }
1883
+ }
1884
+ function createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning) {
1885
+ const errorText = getErrorFromResult(toolResult.result);
1886
+ return {
1887
+ type: "generalTool",
1888
+ id: "",
1889
+ expertKey: "",
1890
+ runId: "",
1891
+ reasoning,
1892
+ skillName,
1893
+ toolName,
1894
+ args: toolCall.args,
1895
+ result: toolResult.result,
1896
+ error: errorText
1897
+ };
1898
+ }
1899
+ function getErrorFromResult(result) {
1900
+ const textPart = result.find((p) => p.type === "textPart");
1901
+ if (!textPart?.text) return void 0;
1902
+ try {
1903
+ const parsed = JSON.parse(textPart.text);
1904
+ if (typeof parsed.error === "string") {
1905
+ return parsed.error;
1906
+ }
1907
+ } catch {
1908
+ const trimmed = textPart.text.trim();
1909
+ if (trimmed.toLowerCase().startsWith("error:") || trimmed.toLowerCase().startsWith("error ")) {
1910
+ return textPart.text;
1911
+ }
1912
+ }
1913
+ return void 0;
1914
+ }
1915
+ function parseStringField(result, field) {
1916
+ const textPart = result.find((p) => p.type === "textPart");
1917
+ if (!textPart?.text) return void 0;
1918
+ try {
1919
+ const parsed = JSON.parse(textPart.text);
1920
+ return typeof parsed[field] === "string" ? parsed[field] : void 0;
1921
+ } catch {
1922
+ return void 0;
1923
+ }
1924
+ }
1925
+ function parseNumberField(result, field) {
1926
+ const textPart = result.find((p) => p.type === "textPart");
1927
+ if (!textPart?.text) return void 0;
1928
+ try {
1929
+ const parsed = JSON.parse(textPart.text);
1930
+ return typeof parsed[field] === "number" ? parsed[field] : void 0;
1931
+ } catch {
1932
+ return void 0;
1933
+ }
1934
+ }
1935
+ function parseRemainingTodosFromResult(result) {
1936
+ const textPart = result.find((p) => p.type === "textPart");
1937
+ if (!textPart?.text) return void 0;
1938
+ try {
1939
+ const parsed = JSON.parse(textPart.text);
1940
+ if (Array.isArray(parsed.remainingTodos)) {
1941
+ return parsed.remainingTodos.map(
1942
+ (t, i) => ({
1943
+ id: typeof t.id === "number" ? t.id : i,
1944
+ title: typeof t.title === "string" ? t.title : "",
1945
+ completed: typeof t.completed === "boolean" ? t.completed : false
1946
+ })
1947
+ );
1948
+ }
1949
+ } catch {
1950
+ }
1951
+ return void 0;
1952
+ }
1953
+ function parseTodosFromResult(result) {
1954
+ const textPart = result.find((p) => p.type === "textPart");
1955
+ if (!textPart?.text) return [];
1956
+ try {
1957
+ const parsed = JSON.parse(textPart.text);
1958
+ if (Array.isArray(parsed.todos)) {
1959
+ return parsed.todos.map(
1960
+ (t, i) => ({
1961
+ id: typeof t.id === "number" ? t.id : i,
1962
+ title: typeof t.title === "string" ? t.title : "",
1963
+ completed: typeof t.completed === "boolean" ? t.completed : false
1964
+ })
1965
+ );
1966
+ }
1967
+ } catch {
1968
+ }
1969
+ return [];
1970
+ }
1971
+ function parseFileInfoFromResult(result) {
1972
+ const textPart = result.find((p) => p.type === "textPart");
1973
+ if (!textPart?.text) return void 0;
1974
+ try {
1975
+ const parsed = JSON.parse(textPart.text);
1976
+ return {
1977
+ exists: typeof parsed.exists === "boolean" ? parsed.exists : true,
1978
+ name: String(parsed.name ?? ""),
1979
+ directory: String(parsed.directory ?? ""),
1980
+ extension: typeof parsed.extension === "string" ? parsed.extension : null,
1981
+ type: parsed.type === "directory" ? "directory" : "file",
1982
+ mimeType: typeof parsed.mimeType === "string" ? parsed.mimeType : null,
1983
+ size: typeof parsed.size === "number" ? parsed.size : 0,
1984
+ sizeFormatted: String(parsed.sizeFormatted ?? ""),
1985
+ created: String(parsed.created ?? ""),
1986
+ modified: String(parsed.modified ?? ""),
1987
+ accessed: String(parsed.accessed ?? "")
1988
+ };
1989
+ } catch {
1990
+ return void 0;
1991
+ }
1992
+ }
1993
+ function parseListDirectoryFromResult(result) {
1994
+ const textPart = result.find((p) => p.type === "textPart");
1995
+ if (!textPart?.text) return void 0;
1996
+ try {
1997
+ const parsed = JSON.parse(textPart.text);
1998
+ if (!Array.isArray(parsed.items)) return void 0;
1999
+ return parsed.items.map(
2000
+ (item) => ({
2001
+ name: String(item.name ?? ""),
2002
+ path: String(item.path ?? ""),
2003
+ type: item.type === "directory" ? "directory" : "file",
2004
+ size: typeof item.size === "number" ? item.size : 0,
2005
+ modified: String(item.modified ?? "")
2006
+ })
2007
+ );
2008
+ } catch {
2009
+ return void 0;
2010
+ }
2011
+ }
2012
+
1317
2013
  // src/utils/env-filter.ts
1318
2014
  var SAFE_ENV_VARS = [
1319
2015
  // System
@@ -1364,6 +2060,24 @@ function getFilteredEnv(additional) {
1364
2060
  return filtered;
1365
2061
  }
1366
2062
 
2063
+ // src/utils/event-filter.ts
2064
+ function validateEventFilter(filter) {
2065
+ const invalid = filter.filter((type) => !isValidEventType(type) && !isValidRuntimeEventType(type));
2066
+ if (invalid.length > 0) {
2067
+ throw new Error(
2068
+ `Invalid event type(s): ${invalid.join(", ")}. Valid event types are: startRun, completeRun, stopRunByError, callTools, etc. See documentation for full list.`
2069
+ );
2070
+ }
2071
+ return filter;
2072
+ }
2073
+ function createFilteredEventListener(listener, allowedTypes) {
2074
+ return (event) => {
2075
+ if (allowedTypes.has(event.type)) {
2076
+ listener(event);
2077
+ }
2078
+ };
2079
+ }
2080
+
1367
2081
  // src/utils/zod-error.ts
1368
2082
  function formatZodError(error) {
1369
2083
  const issues = error.issues.map((issue) => {
@@ -1382,6 +2096,6 @@ function parseWithFriendlyError(schema, data, context) {
1382
2096
  throw new Error(`${prefix}${formatZodError(result.error)}`);
1383
2097
  }
1384
2098
 
1385
- export { BaseAdapter, SAFE_ENV_VARS, amazonBedrockProviderConfigSchema, anthropicProviderConfigSchema, anthropicProviderSkillSchema, anthropicProviderToolNameSchema, attemptCompletion, azureOpenAIProviderToolNameSchema, azureOpenAiProviderConfigSchema, basePartSchema, builtinAnthropicSkillSchema, callDelegate, callInteractiveTool, callTools, checkpointSchema, checkpointStatusSchema, completeRun, continueToNextStep, createCallToolsEvent, createCompleteRunEvent, createEmptyUsage, createEvent, createNormalizedCheckpoint, createResolveToolResultsEvent, createRuntimeEvent, createRuntimeInitEvent, createStartRunEvent, createStreamingTextEvent, createToolMessage, customAnthropicSkillSchema, deepseekProviderConfigSchema, defaultMaxRetries, defaultMaxSteps, defaultPerstackApiBaseUrl, defaultReasoningBudget, defaultTimeout, delegationTargetSchema, domainPatternSchema, envNameRegex, expertKeyRegex, expertMessageSchema, expertNameRegex, expertSchema, expertVersionRegex, fileBinaryPartSchema, fileInlinePartSchema, fileSearchOptionsSchema, fileUrlPartSchema, finishAllToolCalls, finishToolCall, formatZodError, getAdapter, getFilteredEnv, getRegisteredRuntimes, googleGenerativeAiProviderConfigSchema, googleProviderToolNameSchema, googleVertexProviderConfigSchema, hasCustomProviderSkills, headersSchema, imageBinaryPartSchema, imageInlinePartSchema, imageUrlPartSchema, instructionMessageSchema, interactiveSkillSchema, interactiveToolSchema, isAdapterAvailable, jobSchema, jobStatusSchema, knownModels, lockfileExpertSchema, lockfileSchema, lockfileToolDefinitionSchema, maxApplicationNameLength, maxCheckpointToolCallIdLength, maxEnvNameLength, maxExpertDelegateItems, maxExpertDescriptionLength, maxExpertInstructionLength, maxExpertJobFileNameLength, maxExpertJobQueryLength, maxExpertKeyLength, maxExpertNameLength, maxExpertSkillItems, maxExpertTagItems, maxExpertVersionTagLength, maxOrganizationNameLength, maxSkillDescriptionLength, maxSkillEndpointLength, maxSkillInputJsonSchemaLength, maxSkillNameLength, maxSkillPickOmitItems, maxSkillRequiredEnvItems, maxSkillRuleLength, maxSkillToolItems, maxSkillToolNameLength, mcpSseSkillSchema, mcpStdioSkillSchema, messagePartSchema, messageSchema, ollamaProviderConfigSchema, openAiProviderConfigSchema, openaiProviderToolNameSchema, organizationNameRegex, packageWithVersionRegex, parseExpertKey, parseWithFriendlyError, perstackConfigSchema, providerConfigSchema, providerNameSchema, providerTableSchema, providerToolOptionsSchema, reasoningBudgetSchema, registerAdapter, resolveToolResults, resumeToolCalls, retry, runCommandInputSchema, runParamsSchema, runSettingSchema, runtimeNameSchema, skillSchema, startCommandInputSchema, startGeneration, startRun, stepSchema, stopRunByDelegate, stopRunByError, stopRunByExceededMaxSteps, stopRunByInteractiveTool, tagNameRegex, textPartSchema, thinkingPartSchema, toolCallPartSchema, toolCallSchema, toolMessageSchema, toolResultPartSchema, toolResultSchema, urlSafeRegex, usageSchema, userMessageSchema, vertexProviderToolNameSchema, webFetchOptionsSchema, webSearchOptionsSchema };
2099
+ export { BASE_SKILL_PREFIX, BaseAdapter, SAFE_ENV_VARS, activityOrGroupSchema, activitySchema, amazonBedrockProviderConfigSchema, anthropicProviderConfigSchema, anthropicProviderSkillSchema, anthropicProviderToolNameSchema, appendTextFileActivitySchema, attemptCompletion, attemptCompletionActivitySchema, azureOpenAIProviderToolNameSchema, azureOpenAiProviderConfigSchema, basePartSchema, builtinAnthropicSkillSchema, callTools, checkpointSchema, checkpointStatusSchema, clearTodoActivitySchema, completeActivitySchema, completeRun, continueToNextStep, createBaseToolActivity, createCallToolsEvent, createCompleteRunEvent, createDirectoryActivitySchema, createEmptyUsage, createEvent, createFilteredEventListener, createGeneralToolActivity, createNormalizedCheckpoint, createResolveToolResultsEvent, createRuntimeEvent, createRuntimeInitEvent, createStartRunEvent, createStreamingEvent, createToolMessage, customAnthropicSkillSchema, deepseekProviderConfigSchema, defaultMaxRetries, defaultMaxSteps, defaultPerstackApiBaseUrl, defaultReasoningBudget, defaultTimeout, delegateActivitySchema, delegationCompleteActivitySchema, delegationTargetSchema, deleteDirectoryActivitySchema, deleteFileActivitySchema, domainPatternSchema, editTextFileActivitySchema, envNameRegex, errorActivitySchema, execActivitySchema, expertKeyRegex, expertMessageSchema, expertNameRegex, expertSchema, expertVersionRegex, fileBinaryPartSchema, fileInlinePartSchema, fileSearchOptionsSchema, fileUrlPartSchema, finishMcpTools, finishToolCall, formatZodError, generalToolActivitySchema, getActivities, getAdapter, getFileInfoActivitySchema, getFilteredEnv, getRegisteredRuntimes, googleGenerativeAiProviderConfigSchema, googleProviderToolNameSchema, googleVertexProviderConfigSchema, hasCustomProviderSkills, headersSchema, imageBinaryPartSchema, imageInlinePartSchema, imageUrlPartSchema, instructionMessageSchema, interactiveSkillSchema, interactiveToolActivitySchema, interactiveToolSchema, isAdapterAvailable, isValidEventType, isValidRuntimeEventType, jobSchema, jobStatusSchema, knownModels, listDirectoryActivitySchema, lockfileExpertSchema, lockfileSchema, lockfileToolDefinitionSchema, maxApplicationNameLength, maxCheckpointToolCallIdLength, maxEnvNameLength, maxExpertDelegateItems, maxExpertDescriptionLength, maxExpertInstructionLength, maxExpertJobFileNameLength, maxExpertJobQueryLength, maxExpertKeyLength, maxExpertNameLength, maxExpertSkillItems, maxExpertTagItems, maxExpertVersionTagLength, maxOrganizationNameLength, maxSkillDescriptionLength, maxSkillEndpointLength, maxSkillInputJsonSchemaLength, maxSkillNameLength, maxSkillPickOmitItems, maxSkillRequiredEnvItems, maxSkillRuleLength, maxSkillToolItems, maxSkillToolNameLength, mcpSseSkillSchema, mcpStdioSkillSchema, messagePartSchema, messageSchema, moveFileActivitySchema, ollamaProviderConfigSchema, openAiProviderConfigSchema, openaiProviderToolNameSchema, organizationNameRegex, packageWithVersionRegex, parallelActivitiesGroupSchema, parseExpertKey, parseWithFriendlyError, perstackConfigSchema, proceedToInteractiveTools, providerConfigSchema, providerNameSchema, providerTableSchema, providerToolOptionsSchema, queryActivitySchema, readImageFileActivitySchema, readPdfFileActivitySchema, readTextFileActivitySchema, reasoningBudgetSchema, registerAdapter, resolveToolResults, resumeFromStop, resumeToolCalls, retry, retryActivitySchema, runCommandInputSchema, runParamsSchema, runSettingSchema, runtimeNameSchema, skillSchema, skipDelegates, startCommandInputSchema, startGeneration, startRun, stepSchema, stopRunByDelegate, stopRunByError, stopRunByExceededMaxSteps, stopRunByInteractiveTool, tagNameRegex, textPartSchema, thinkingPartSchema, todoActivitySchema, toolCallPartSchema, toolCallSchema, toolMessageSchema, toolResultPartSchema, toolResultSchema, urlSafeRegex, usageSchema, userMessageSchema, validateEventFilter, vertexProviderToolNameSchema, webFetchOptionsSchema, webSearchOptionsSchema, writeTextFileActivitySchema };
1386
2100
  //# sourceMappingURL=index.js.map
1387
2101
  //# sourceMappingURL=index.js.map