@perstack/core 0.0.57 → 0.0.59

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
@@ -492,7 +492,8 @@ const baseActivitySchema = z.object({
492
492
  expertKey: z.string(),
493
493
  runId: z.string()
494
494
  }).optional(),
495
- reasoning: z.string().optional()
495
+ reasoning: z.string().optional(),
496
+ timestamp: z.number()
496
497
  });
497
498
  const queryActivitySchema = baseActivitySchema.extend({
498
499
  type: z.literal("query"),
@@ -1649,6 +1650,7 @@ function getActivities(params) {
1649
1650
  const { status, delegateTo, runId, stepNumber } = checkpoint;
1650
1651
  const expertKey = checkpoint.expert.key;
1651
1652
  const reasoning = extractReasoning(step.newMessages);
1653
+ const ts = step.startedAt;
1652
1654
  let queryActivity;
1653
1655
  if (stepNumber === 1 && step.inputMessages) {
1654
1656
  const userMessage = step.inputMessages.find((m) => m.type === "userMessage");
@@ -1659,104 +1661,110 @@ function getActivities(params) {
1659
1661
  id: "",
1660
1662
  expertKey,
1661
1663
  runId,
1664
+ timestamp: step.startedAt,
1662
1665
  text: textPart.text
1663
1666
  };
1664
1667
  }
1665
1668
  }
1666
1669
  const prependQuery = (result) => queryActivity ? [queryActivity, ...result] : result;
1667
- if (status === "stoppedByError") return prependQuery([createErrorActivity(checkpoint, reasoning)]);
1670
+ if (status === "stoppedByError") return prependQuery([createErrorActivity(checkpoint, reasoning, ts)]);
1668
1671
  if (status === "stoppedByDelegate") {
1669
- if (!delegateTo || delegateTo.length === 0) return prependQuery([createRetryActivity(step.newMessages, reasoning, "Delegate status but no delegation targets")]);
1670
- return prependQuery(wrapInGroupIfParallel(delegateTo.map((d) => createDelegateActivity(d, reasoning)), reasoning, expertKey, runId, stepNumber));
1672
+ if (!delegateTo || delegateTo.length === 0) return prependQuery([createRetryActivity(step.newMessages, reasoning, ts, "Delegate status but no delegation targets")]);
1673
+ return prependQuery(wrapInGroupIfParallel(delegateTo.map((d) => createDelegateActivity(d, reasoning, ts)), reasoning, expertKey, runId, stepNumber));
1671
1674
  }
1672
1675
  if (status === "stoppedByInteractiveTool") {
1673
1676
  const toolCalls = step.toolCalls ?? [];
1674
- if (toolCalls.length === 0) return prependQuery([createRetryActivity(step.newMessages, reasoning)]);
1675
- return prependQuery(wrapInGroupIfParallel(toolCalls.map((tc) => createInteractiveToolActivity(tc.skillName, tc.toolName, tc, reasoning)), reasoning, expertKey, runId, stepNumber));
1677
+ if (toolCalls.length === 0) return prependQuery([createRetryActivity(step.newMessages, reasoning, ts)]);
1678
+ return prependQuery(wrapInGroupIfParallel(toolCalls.map((tc) => createInteractiveToolActivity(tc.skillName, tc.toolName, tc, reasoning, ts)), reasoning, expertKey, runId, stepNumber));
1676
1679
  }
1677
1680
  const toolCalls = step.toolCalls ?? [];
1678
1681
  const toolResults = step.toolResults ?? [];
1679
1682
  if (toolCalls.length === 0) {
1680
- if (status === "completed") return prependQuery([createCompleteActivity(step.newMessages, reasoning)]);
1683
+ if (status === "completed") return prependQuery([createCompleteActivity(step.newMessages, reasoning, ts)]);
1681
1684
  if (status === "proceeding" || status === "init") return prependQuery([]);
1682
- return prependQuery([createRetryActivity(step.newMessages, reasoning)]);
1685
+ return prependQuery([createRetryActivity(step.newMessages, reasoning, ts)]);
1683
1686
  }
1684
1687
  const toolActivities = [];
1685
1688
  for (const toolCall of toolCalls) {
1686
1689
  const toolResult = toolResults.find((tr) => tr.id === toolCall.id);
1687
1690
  if (!toolResult) continue;
1688
1691
  const { skillName, toolName } = toolCall;
1689
- if (skillName.startsWith(BASE_SKILL_PREFIX)) toolActivities.push(createBaseToolActivity(toolName, toolCall, toolResult, reasoning));
1690
- else toolActivities.push(createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning));
1692
+ if (skillName.startsWith(BASE_SKILL_PREFIX)) toolActivities.push(createBaseToolActivity(toolName, toolCall, toolResult, reasoning, ts));
1693
+ else toolActivities.push(createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning, ts));
1691
1694
  }
1692
1695
  if (toolActivities.length === 0) {
1693
- if (status === "completed") return prependQuery([createCompleteActivity(step.newMessages, reasoning)]);
1696
+ if (status === "completed") return prependQuery([createCompleteActivity(step.newMessages, reasoning, ts)]);
1694
1697
  if (status === "proceeding" || status === "init") return prependQuery([]);
1695
- return prependQuery([createRetryActivity(step.newMessages, reasoning)]);
1698
+ return prependQuery([createRetryActivity(step.newMessages, reasoning, ts)]);
1696
1699
  }
1697
1700
  const result = wrapInGroupIfParallel(toolActivities, reasoning, expertKey, runId, stepNumber);
1698
- if (status === "completed") result.push(createCompleteActivity(step.newMessages, void 0));
1701
+ if (status === "completed") result.push(createCompleteActivity(step.newMessages, void 0, ts));
1699
1702
  return prependQuery(result);
1700
1703
  }
1701
- function createCompleteActivity(newMessages, reasoning) {
1704
+ function createCompleteActivity(newMessages, reasoning, timestamp) {
1702
1705
  return {
1703
1706
  type: "complete",
1704
1707
  id: "",
1705
1708
  expertKey: "",
1706
1709
  runId: "",
1710
+ timestamp,
1707
1711
  reasoning,
1708
1712
  text: ([...newMessages].reverse().find((m) => m.type === "expertMessage")?.contents.find((c) => c.type === "textPart"))?.text ?? ""
1709
1713
  };
1710
1714
  }
1711
- function createDelegateActivity(delegate, reasoning) {
1715
+ function createDelegateActivity(delegate, reasoning, timestamp) {
1712
1716
  return {
1713
1717
  type: "delegate",
1714
1718
  id: "",
1715
1719
  expertKey: "",
1716
1720
  runId: "",
1721
+ timestamp,
1717
1722
  reasoning,
1718
1723
  delegateExpertKey: delegate.expert.key,
1719
1724
  query: delegate.query
1720
1725
  };
1721
1726
  }
1722
- function createInteractiveToolActivity(skillName, toolName, toolCall, reasoning) {
1727
+ function createInteractiveToolActivity(skillName, toolName, toolCall, reasoning, timestamp) {
1723
1728
  return {
1724
1729
  type: "interactiveTool",
1725
1730
  id: "",
1726
1731
  expertKey: "",
1727
1732
  runId: "",
1733
+ timestamp,
1728
1734
  reasoning,
1729
1735
  skillName,
1730
1736
  toolName,
1731
1737
  args: toolCall.args
1732
1738
  };
1733
1739
  }
1734
- function createRetryActivity(newMessages, reasoning, customError) {
1740
+ function createRetryActivity(newMessages, reasoning, timestamp, customError) {
1735
1741
  const textPart = newMessages[newMessages.length - 1]?.contents.find((c) => c.type === "textPart");
1736
1742
  return {
1737
1743
  type: "retry",
1738
1744
  id: "",
1739
1745
  expertKey: "",
1740
1746
  runId: "",
1747
+ timestamp,
1741
1748
  reasoning,
1742
1749
  error: customError ?? "No tool call or result found",
1743
1750
  message: textPart?.text ?? ""
1744
1751
  };
1745
1752
  }
1746
- function createErrorActivity(checkpoint, reasoning) {
1753
+ function createErrorActivity(checkpoint, reasoning, timestamp) {
1747
1754
  const error = checkpoint.error;
1748
1755
  return {
1749
1756
  type: "error",
1750
1757
  id: "",
1751
1758
  expertKey: "",
1752
1759
  runId: "",
1760
+ timestamp,
1753
1761
  reasoning,
1754
1762
  error: error?.message ?? "Unknown error",
1755
1763
  errorName: error?.name,
1756
1764
  isRetryable: error?.isRetryable
1757
1765
  };
1758
1766
  }
1759
- function createBaseToolActivity(toolName, toolCall, toolResult, reasoning) {
1767
+ function createBaseToolActivity(toolName, toolCall, toolResult, reasoning, timestamp = 0) {
1760
1768
  const args = toolCall.args;
1761
1769
  const resultContents = toolResult.result;
1762
1770
  const errorText = getErrorFromResult(resultContents);
@@ -1764,7 +1772,8 @@ function createBaseToolActivity(toolName, toolCall, toolResult, reasoning) {
1764
1772
  id: "",
1765
1773
  expertKey: "",
1766
1774
  runId: "",
1767
- reasoning
1775
+ reasoning,
1776
+ timestamp
1768
1777
  };
1769
1778
  switch (toolName) {
1770
1779
  case "attemptCompletion": {
@@ -1878,16 +1887,17 @@ function createBaseToolActivity(toolName, toolCall, toolResult, reasoning) {
1878
1887
  resultExpertKey: parseStringField(resultContents, "expertKey"),
1879
1888
  error: errorText
1880
1889
  };
1881
- default: return createGeneralToolActivity(toolCall.skillName, toolName, toolCall, toolResult, reasoning);
1890
+ default: return createGeneralToolActivity(toolCall.skillName, toolName, toolCall, toolResult, reasoning, timestamp);
1882
1891
  }
1883
1892
  }
1884
- function createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning) {
1893
+ function createGeneralToolActivity(skillName, toolName, toolCall, toolResult, reasoning, timestamp = 0) {
1885
1894
  const errorText = getErrorFromResult(toolResult.result);
1886
1895
  return {
1887
1896
  type: "generalTool",
1888
1897
  id: "",
1889
1898
  expertKey: "",
1890
1899
  runId: "",
1900
+ timestamp,
1891
1901
  reasoning,
1892
1902
  skillName,
1893
1903
  toolName,
@@ -2027,6 +2037,19 @@ function createFilteredEventListener(listener, allowedTypes) {
2027
2037
  };
2028
2038
  }
2029
2039
 
2040
+ //#endregion
2041
+ //#region src/utils/truncate.ts
2042
+ const MAX_TOOL_OUTPUT_CHARS = 3e4;
2043
+ function truncateText(text, maxChars = MAX_TOOL_OUTPUT_CHARS) {
2044
+ if (text.length <= maxChars) return text;
2045
+ const marker = `\n\n... [truncated: ${text.length - maxChars} characters removed from middle of ${text.length} total] ...\n\n`;
2046
+ const available = maxChars - marker.length;
2047
+ if (available <= 0) return text.slice(0, maxChars);
2048
+ const head = Math.floor(available * .8);
2049
+ const tail = available - head;
2050
+ return text.slice(0, head) + marker + text.slice(text.length - tail);
2051
+ }
2052
+
2030
2053
  //#endregion
2031
2054
  //#region src/utils/zod-error.ts
2032
2055
  function formatZodError(error) {
@@ -2041,5 +2064,5 @@ function parseWithFriendlyError(schema, data, context) {
2041
2064
  }
2042
2065
 
2043
2066
  //#endregion
2044
- export { BASE_SKILL_PREFIX, PerstackError, SAFE_ENV_VARS, activityOrGroupSchema, activitySchema, addDelegateActivitySchema, addSkillActivitySchema, amazonBedrockProviderConfigSchema, anthropicProviderConfigSchema, anthropicProviderSkillSchema, anthropicProviderToolNameSchema, attemptCompletionActivitySchema, azureOpenAIProviderToolNameSchema, azureOpenAiProviderConfigSchema, basePartSchema, builtinAnthropicSkillSchema, callTools, checkpointSchema, checkpointStatusSchema, clearTodoActivitySchema, completeActivitySchema, completeRun, continueToNextStep, createBaseToolActivity, createCallToolsEvent, createCompleteRunEvent, createEmptyUsage, createEvent, createExpertActivitySchema, createFilteredEventListener, createGeneralToolActivity, createNormalizedCheckpoint, createResolveToolResultsEvent, createRuntimeEvent, createRuntimeInitEvent, createStartRunEvent, createStreamingEvent, createToolMessage, customAnthropicSkillSchema, deepseekProviderConfigSchema, defaultMaxRetries, defaultPerstackApiBaseUrl, defaultReasoningBudget, defaultTimeout, delegateActivitySchema, delegationCompleteActivitySchema, delegationTargetSchema, domainPatternSchema, editTextFileActivitySchema, errorActivitySchema, execActivitySchema, expertBaseSchema, expertKeyRegex, expertMessageSchema, expertNameRegex, expertSchema, expertVersionRegex, fileBinaryPartSchema, fileInlinePartSchema, fileSearchOptionsSchema, fileUrlPartSchema, finishMcpTools, finishToolCall, formatZodError, generalToolActivitySchema, getActivities, getExpertScope, getExpertShortName, getExpertType, getFilteredEnv, googleGenerativeAiProviderConfigSchema, googleProviderToolNameSchema, googleVertexProviderConfigSchema, headersSchema, imageBinaryPartSchema, imageInlinePartSchema, imageUrlPartSchema, instructionMessageSchema, interactiveSkillSchema, interactiveToolActivitySchema, interactiveToolSchema, isCoordinatorExpert, isDelegateExpert, isPrivateOrLocalIP, isValidEventType, isValidRuntimeEventType, jobSchema, jobStatusSchema, knownModels, lockfileExpertSchema, lockfileSchema, lockfileToolDefinitionSchema, maxExpertNameLength, maxSkillNameLength, maxSkillToolNameLength, mcpSseSkillSchema, mcpStdioSkillSchema, messagePartSchema, messageSchema, modelTierSchema, ollamaProviderConfigSchema, openAiProviderConfigSchema, openaiProviderToolNameSchema, parallelActivitiesGroupSchema, parseExpertKey, parseWithFriendlyError, perstackConfigSchema, proceedToInteractiveTools, providerConfigSchema, providerNameSchema, providerTableSchema, providerToolOptionsSchema, queryActivitySchema, readImageFileActivitySchema, readPdfFileActivitySchema, readTextFileActivitySchema, reasoningBudgetSchema, removeDelegateActivitySchema, removeSkillActivitySchema, resolveModelTier, resolveToolResults, resumeFromStop, resumeToolCalls, retry, retryActivitySchema, runCommandInputSchema, runParamsSchema, runSettingSchema, runtimeVersionSchema, skillSchema, skipDelegates, startCommandInputSchema, startGeneration, startRun, stepSchema, stopRunByDelegate, stopRunByError, stopRunByInteractiveTool, tagNameRegex, textPartSchema, thinkingPartSchema, todoActivitySchema, toolCallPartSchema, toolCallSchema, toolMessageSchema, toolResultPartSchema, toolResultSchema, usageSchema, userMessageSchema, validateAllDelegations, validateDelegation, validateEventFilter, vertexProviderToolNameSchema, webFetchOptionsSchema, webSearchOptionsSchema, writeTextFileActivitySchema };
2067
+ export { BASE_SKILL_PREFIX, MAX_TOOL_OUTPUT_CHARS, PerstackError, SAFE_ENV_VARS, activityOrGroupSchema, activitySchema, addDelegateActivitySchema, addSkillActivitySchema, amazonBedrockProviderConfigSchema, anthropicProviderConfigSchema, anthropicProviderSkillSchema, anthropicProviderToolNameSchema, attemptCompletionActivitySchema, azureOpenAIProviderToolNameSchema, azureOpenAiProviderConfigSchema, basePartSchema, builtinAnthropicSkillSchema, callTools, checkpointSchema, checkpointStatusSchema, clearTodoActivitySchema, completeActivitySchema, completeRun, continueToNextStep, createBaseToolActivity, createCallToolsEvent, createCompleteRunEvent, createEmptyUsage, createEvent, createExpertActivitySchema, createFilteredEventListener, createGeneralToolActivity, createNormalizedCheckpoint, createResolveToolResultsEvent, createRuntimeEvent, createRuntimeInitEvent, createStartRunEvent, createStreamingEvent, createToolMessage, customAnthropicSkillSchema, deepseekProviderConfigSchema, defaultMaxRetries, defaultPerstackApiBaseUrl, defaultReasoningBudget, defaultTimeout, delegateActivitySchema, delegationCompleteActivitySchema, delegationTargetSchema, domainPatternSchema, editTextFileActivitySchema, errorActivitySchema, execActivitySchema, expertBaseSchema, expertKeyRegex, expertMessageSchema, expertNameRegex, expertSchema, expertVersionRegex, fileBinaryPartSchema, fileInlinePartSchema, fileSearchOptionsSchema, fileUrlPartSchema, finishMcpTools, finishToolCall, formatZodError, generalToolActivitySchema, getActivities, getExpertScope, getExpertShortName, getExpertType, getFilteredEnv, googleGenerativeAiProviderConfigSchema, googleProviderToolNameSchema, googleVertexProviderConfigSchema, headersSchema, imageBinaryPartSchema, imageInlinePartSchema, imageUrlPartSchema, instructionMessageSchema, interactiveSkillSchema, interactiveToolActivitySchema, interactiveToolSchema, isCoordinatorExpert, isDelegateExpert, isPrivateOrLocalIP, isValidEventType, isValidRuntimeEventType, jobSchema, jobStatusSchema, knownModels, lockfileExpertSchema, lockfileSchema, lockfileToolDefinitionSchema, maxExpertNameLength, maxSkillNameLength, maxSkillToolNameLength, mcpSseSkillSchema, mcpStdioSkillSchema, messagePartSchema, messageSchema, modelTierSchema, ollamaProviderConfigSchema, openAiProviderConfigSchema, openaiProviderToolNameSchema, parallelActivitiesGroupSchema, parseExpertKey, parseWithFriendlyError, perstackConfigSchema, proceedToInteractiveTools, providerConfigSchema, providerNameSchema, providerTableSchema, providerToolOptionsSchema, queryActivitySchema, readImageFileActivitySchema, readPdfFileActivitySchema, readTextFileActivitySchema, reasoningBudgetSchema, removeDelegateActivitySchema, removeSkillActivitySchema, resolveModelTier, resolveToolResults, resumeFromStop, resumeToolCalls, retry, retryActivitySchema, runCommandInputSchema, runParamsSchema, runSettingSchema, runtimeVersionSchema, skillSchema, skipDelegates, startCommandInputSchema, startGeneration, startRun, stepSchema, stopRunByDelegate, stopRunByError, stopRunByInteractiveTool, tagNameRegex, textPartSchema, thinkingPartSchema, todoActivitySchema, toolCallPartSchema, toolCallSchema, toolMessageSchema, toolResultPartSchema, toolResultSchema, truncateText, usageSchema, userMessageSchema, validateAllDelegations, validateDelegation, validateEventFilter, vertexProviderToolNameSchema, webFetchOptionsSchema, webSearchOptionsSchema, writeTextFileActivitySchema };
2045
2068
  //# sourceMappingURL=index.js.map