sidekick-shared 0.19.1 → 0.19.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.
- package/README.md +22 -3
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +7 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +22 -4
- package/dist/schemas/assistantTurn.d.ts +123 -0
- package/dist/schemas/assistantTurn.js +67 -0
- package/dist/schemas/index.d.ts +6 -3
- package/dist/schemas/index.js +16 -4
- package/dist/turns/assistantTurn.d.ts +69 -0
- package/dist/turns/assistantTurn.js +314 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,11 +27,12 @@ npm install sidekick-shared
|
|
|
27
27
|
| **Search** | Cross-session full-text search, advanced filtering (substring, fuzzy, regex, date) |
|
|
28
28
|
| **Aggregation** | Event aggregation, frequency tracking, activity heatmaps, pattern extraction |
|
|
29
29
|
| **Session Context** | Provider-neutral context evidence snapshots (`buildSessionContextSnapshot()`, `calculateSessionContextPressure()`, `createSessionContextProjector()`, `readSessionContextSnapshot()`): layered evidence sources, low/medium/high context pressure, and observed capabilities (tools, MCP servers, permission mode, rate limits) |
|
|
30
|
+
| **Assistant Turns** | Browser-safe process/answer projection for provider-normalized assistant turns (`segmentAssistantTurn()`, `assistantTurnEventsFromSessionEvents()`), including reasoning blocks, compact tool groups, and Claude `Task` subagent refs without prompt leakage |
|
|
30
31
|
| **Report** | Self-contained HTML session report generation |
|
|
31
32
|
| **Credentials** | Claude Max OAuth credential reading from `~/.claude/.credentials.json` |
|
|
32
33
|
| **Quota** | Claude Max subscription quota fetching (5-hour and 7-day windows) and Codex rate-limit extraction from event streams |
|
|
33
34
|
| **Provider Status** | API health checking via status.claude.com and status.openai.com (indicator, components, incidents) |
|
|
34
|
-
| **Schemas** | Zod schemas for runtime validation of data crossing process/IPC boundaries — JSONL session events (`sessionEventSchema`, `messageUsageSchema`, `sessionMessageSchema`), quota, account status, and quota history — plus `extractSessionEvents()` to unwrap `progress`-wrapped events. Also published fs-free via the [`sidekick-shared/schemas`](#supported-import-paths) subpath |
|
|
35
|
+
| **Schemas** | Zod schemas for runtime validation of data crossing process/IPC boundaries — JSONL session events (`sessionEventSchema`, `messageUsageSchema`, `sessionMessageSchema`), assistant turns, quota, account status, and quota history — plus `extractSessionEvents()` to unwrap `progress`-wrapped events. Also published fs-free via the [`sidekick-shared/schemas`](#supported-import-paths) subpath |
|
|
35
36
|
| **Extractors** | Pure functions for single-event processing: `extractTokenUsage()`, `extractToolCall()` (top-level `tool_use`), `extractToolCalls()` (assistant content blocks) |
|
|
36
37
|
| **Model Info & Pricing** | Model family parsing (Anthropic / OpenAI / Google, including legacy `claude-3-opus-…` and `claude-3-5-sonnet-…` IDs), context-window lookup (including Fable 5 / Opus 4.8 / Opus 4.7 / Sonnet 4.7 1M and GPT-5.x variants), pricing tables with optional LiteLLM hydration, null-aware cost (`calculateCost()`), provenance-preserving cost (`calculateCostWithProvenance()`, `mergeCostSources()`), and display helpers (`shortModelName()`, `getModelDisplayInfo()`, `compareModelIds()`, `sortModelIds()`, `formatCost()`) |
|
|
37
38
|
| **Quota Polling** | `QuotaPoller` class with exponential backoff, active/idle intervals, and cached fallback |
|
|
@@ -48,13 +49,13 @@ npm install sidekick-shared
|
|
|
48
49
|
| Path | Runtime | What it exposes |
|
|
49
50
|
|-----------------------------------|-----------------------------|--------------------------------------------------------------------|
|
|
50
51
|
| `sidekick-shared` | Node (CLI, extension host) | Full public API (readers, providers, parsers, pricing, …). |
|
|
51
|
-
| `sidekick-shared/browser` | **Browser / webview** | Pure helpers: context-window lookup, model parsing, cost math.
|
|
52
|
+
| `sidekick-shared/browser` | **Browser / webview** | Pure helpers: context-window lookup, model parsing, cost math, assistant turn projection. |
|
|
52
53
|
| `sidekick-shared/node` | Node only | LiteLLM pricing catalog hydration (`fs` + `path`). |
|
|
53
54
|
| `sidekick-shared/phrases` | Any runtime | Phrase arrays + `getRandomPhrase()`. |
|
|
54
55
|
| `sidekick-shared/modelContext` | Any runtime | Direct access to the context-window module. |
|
|
55
56
|
| `sidekick-shared/modelInfo` | Any runtime | Direct access to model parsing and cost math. |
|
|
56
57
|
| `sidekick-shared/formatting` | Any runtime | Direct access to pure token and duration display helpers. |
|
|
57
|
-
| `sidekick-shared/schemas` | Any runtime | Pure Zod boundary schemas (session events, quota, account status, quota history) — fs-free, no Node builtins. |
|
|
58
|
+
| `sidekick-shared/schemas` | Any runtime | Pure Zod boundary schemas (session events, assistant turns, quota, account status, quota history) — fs-free, no Node builtins. |
|
|
58
59
|
|
|
59
60
|
### Browser / webview runtimes
|
|
60
61
|
|
|
@@ -69,6 +70,7 @@ import {
|
|
|
69
70
|
formatCost,
|
|
70
71
|
formatTokenCount,
|
|
71
72
|
formatDurationMs,
|
|
73
|
+
segmentAssistantTurn,
|
|
72
74
|
} from 'sidekick-shared/browser';
|
|
73
75
|
```
|
|
74
76
|
|
|
@@ -202,6 +204,23 @@ if (provider) {
|
|
|
202
204
|
|
|
203
205
|
Use `createSessionContextProjector()` for incremental updates as new events stream in, or `calculateSessionContextPressure(contextTokens, contextWindow)` for the pressure band alone.
|
|
204
206
|
|
|
207
|
+
### Project an assistant turn into Process + Answer
|
|
208
|
+
|
|
209
|
+
Build a compact UI-safe projection from provider-normalized turn events. The final contiguous text run becomes `answer`; earlier narration, tools, and reasoning stay in `process` / `reasoningBlocks`.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import {
|
|
213
|
+
assistantTurnEventsFromSessionEvents,
|
|
214
|
+
segmentAssistantTurn,
|
|
215
|
+
} from 'sidekick-shared/browser';
|
|
216
|
+
|
|
217
|
+
const projection = segmentAssistantTurn(assistantTurnEventsFromSessionEvents(sessionEvents));
|
|
218
|
+
|
|
219
|
+
console.log(projection.answer);
|
|
220
|
+
console.log(projection.process.steps);
|
|
221
|
+
console.log(projection.subagents); // Claude Task spawns, prompt text omitted
|
|
222
|
+
```
|
|
223
|
+
|
|
205
224
|
### Format shared dashboard values
|
|
206
225
|
|
|
207
226
|
```typescript
|
package/dist/browser.d.ts
CHANGED
|
@@ -12,5 +12,7 @@ export { formatDurationMs, formatTokenCount } from './formatting';
|
|
|
12
12
|
export type { FormatDurationMsOptions, FormatTokenCountOptions } from './formatting';
|
|
13
13
|
export { buildSessionContextSnapshot, calculateSessionContextPressure, createSessionContextProjector, } from './context/sessionContext';
|
|
14
14
|
export type { BuildSessionContextSnapshotOptions, SessionContextCapabilities, SessionContextLayerBreakdown, SessionContextPressure, SessionContextProjector, SessionContextSnapshot, SessionContextSource, SessionContextSourceType, } from './context/sessionContext';
|
|
15
|
+
export { assistantTurnEventsFromSessionEvents, extractTurnSubagents, isAssistantTurnSubagentTool, reasoningSummary, segmentAssistantTurn, } from './turns/assistantTurn';
|
|
16
|
+
export type { AssistantTurnEvent, AssistantTurnEventType, AssistantTurnProcess, AssistantTurnProcessStep, AssistantTurnProjection, AssistantTurnSubagent, AssistantTurnSubagentStatus, AssistantTurnToolRef, ExtractTurnSubagentsOptions, ReasoningSummary, SegmentAssistantTurnOptions, } from './turns/assistantTurn';
|
|
15
17
|
export { parseModelId, getModelPricing, getModelInfo, calculateCost, calculateCostWithPricing, calculateCostWithProvenance, mergeCostSources, shortModelName, getModelDisplayInfo, compareModelIds, sortModelIds, formatCost, } from './modelInfo';
|
|
16
18
|
export type { ModelPricing, CostTokenUsage, CostSource, CostProvenanceInput, CostWithProvenance, ModelProvider, ParsedModelId, ModelInfo, ModelDisplayInfo, } from './modelInfo';
|
package/dist/browser.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* For pricing hydration (LiteLLM catalog refresh), use `sidekick-shared/node`.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.formatCost = exports.sortModelIds = exports.compareModelIds = exports.getModelDisplayInfo = exports.shortModelName = exports.mergeCostSources = exports.calculateCostWithProvenance = exports.calculateCostWithPricing = exports.calculateCost = exports.getModelInfo = exports.getModelPricing = exports.parseModelId = exports.createSessionContextProjector = exports.calculateSessionContextPressure = exports.buildSessionContextSnapshot = exports.formatTokenCount = exports.formatDurationMs = exports.DEFAULT_CONTEXT_WINDOW = exports.getModelContextWindowSize = void 0;
|
|
12
|
+
exports.formatCost = exports.sortModelIds = exports.compareModelIds = exports.getModelDisplayInfo = exports.shortModelName = exports.mergeCostSources = exports.calculateCostWithProvenance = exports.calculateCostWithPricing = exports.calculateCost = exports.getModelInfo = exports.getModelPricing = exports.parseModelId = exports.segmentAssistantTurn = exports.reasoningSummary = exports.isAssistantTurnSubagentTool = exports.extractTurnSubagents = exports.assistantTurnEventsFromSessionEvents = exports.createSessionContextProjector = exports.calculateSessionContextPressure = exports.buildSessionContextSnapshot = exports.formatTokenCount = exports.formatDurationMs = exports.DEFAULT_CONTEXT_WINDOW = exports.getModelContextWindowSize = void 0;
|
|
13
13
|
var modelContext_1 = require("./modelContext");
|
|
14
14
|
Object.defineProperty(exports, "getModelContextWindowSize", { enumerable: true, get: function () { return modelContext_1.getModelContextWindowSize; } });
|
|
15
15
|
Object.defineProperty(exports, "DEFAULT_CONTEXT_WINDOW", { enumerable: true, get: function () { return modelContext_1.DEFAULT_CONTEXT_WINDOW; } });
|
|
@@ -20,6 +20,12 @@ var sessionContext_1 = require("./context/sessionContext");
|
|
|
20
20
|
Object.defineProperty(exports, "buildSessionContextSnapshot", { enumerable: true, get: function () { return sessionContext_1.buildSessionContextSnapshot; } });
|
|
21
21
|
Object.defineProperty(exports, "calculateSessionContextPressure", { enumerable: true, get: function () { return sessionContext_1.calculateSessionContextPressure; } });
|
|
22
22
|
Object.defineProperty(exports, "createSessionContextProjector", { enumerable: true, get: function () { return sessionContext_1.createSessionContextProjector; } });
|
|
23
|
+
var assistantTurn_1 = require("./turns/assistantTurn");
|
|
24
|
+
Object.defineProperty(exports, "assistantTurnEventsFromSessionEvents", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventsFromSessionEvents; } });
|
|
25
|
+
Object.defineProperty(exports, "extractTurnSubagents", { enumerable: true, get: function () { return assistantTurn_1.extractTurnSubagents; } });
|
|
26
|
+
Object.defineProperty(exports, "isAssistantTurnSubagentTool", { enumerable: true, get: function () { return assistantTurn_1.isAssistantTurnSubagentTool; } });
|
|
27
|
+
Object.defineProperty(exports, "reasoningSummary", { enumerable: true, get: function () { return assistantTurn_1.reasoningSummary; } });
|
|
28
|
+
Object.defineProperty(exports, "segmentAssistantTurn", { enumerable: true, get: function () { return assistantTurn_1.segmentAssistantTurn; } });
|
|
23
29
|
var modelInfo_1 = require("./modelInfo");
|
|
24
30
|
Object.defineProperty(exports, "parseModelId", { enumerable: true, get: function () { return modelInfo_1.parseModelId; } });
|
|
25
31
|
Object.defineProperty(exports, "getModelPricing", { enumerable: true, get: function () { return modelInfo_1.getModelPricing; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export { composeContext } from './context/composer';
|
|
|
52
52
|
export type { Fidelity, ContextResult } from './context/composer';
|
|
53
53
|
export { buildSessionContextSnapshot, calculateSessionContextPressure, createSessionContextProjector, readSessionContextSnapshot, } from './context/sessionContext';
|
|
54
54
|
export type { BuildSessionContextSnapshotOptions, ReadSessionContextSnapshotOptions, SessionContextCapabilities, SessionContextLayerBreakdown, SessionContextPressure, SessionContextProjector, SessionContextSnapshot, SessionContextSource, SessionContextSourceType, } from './context/sessionContext';
|
|
55
|
+
export { assistantTurnEventsFromSessionEvents, extractTurnSubagents, isAssistantTurnSubagentTool, reasoningSummary, segmentAssistantTurn, } from './turns/assistantTurn';
|
|
56
|
+
export type { AssistantTurnEvent, AssistantTurnEventType, AssistantTurnProcess, AssistantTurnProcessStep, AssistantTurnProjection, AssistantTurnSubagent, AssistantTurnSubagentStatus, AssistantTurnToolRef, ExtractTurnSubagentsOptions, ReasoningSummary, SegmentAssistantTurnOptions, } from './turns/assistantTurn';
|
|
55
57
|
export { PlanExtractor, parsePlanMarkdown as parsePlanMarkdownShared, extractProposedPlan as extractProposedPlanShared } from './parsers/planExtractor';
|
|
56
58
|
export type { ExtractedPlan, ExtractedPlanStep } from './parsers/planExtractor';
|
|
57
59
|
export { parseChangelog } from './parsers/changelogParser';
|
|
@@ -126,6 +128,7 @@ export { messageUsageSchema, sessionMessageSchema, sessionEventSchema, permissio
|
|
|
126
128
|
export { quotaWindowSchema, quotaStateSchema, quotaFailureKindSchema, quotaProviderIdSchema, quotaSourceSchema, peakHoursStateSchema, quotaFailureDescriptorSchema, runtimeQuotaProviderSchema, providerQuotaStateSchema, claudeProviderQuotaStateSchema, codexProviderQuotaStateSchema, providerQuotaMapSchema, } from './schemas/quota';
|
|
127
129
|
export { quotaHistoryRuntimeProviderSchema, quotaHistorySampleSchema, quotaHistoryDailyBucketSchema, } from './schemas/quotaHistory';
|
|
128
130
|
export { activeProviderAccountStatusSchema, activeAccountStatusSchema, } from './schemas/accountStatus';
|
|
131
|
+
export { assistantTurnEventSchema, assistantTurnEventTypeSchema, assistantTurnNarrationStepSchema, assistantTurnProcessSchema, assistantTurnProcessStepSchema, assistantTurnProjectionSchema, assistantTurnSubagentSchema, assistantTurnSubagentStatusSchema, assistantTurnToolGroupStepSchema, assistantTurnToolRefSchema, } from './schemas/assistantTurn';
|
|
129
132
|
export { fetchProviderStatus, fetchOpenAIStatus } from './providerStatus';
|
|
130
133
|
export type { ProviderStatusState } from './providerStatus';
|
|
131
134
|
export { createPeakHoursNotApplicableState, fetchPeakHoursStatus, isClaudeCodeSessionProvider, scopePeakHoursToSessionProvider, } from './peakHours';
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.findActiveClaudeSession = exports.discoverSessionDirectory = exports.getClaudeSessionDirectory = exports.encodeClaudeWorkspacePath = exports.detectSessionActivity = exports.extractTaskInfo = exports.scanSubagentDir = exports.normalizeCodexToolInput = exports.normalizeCodexToolName = exports.extractPatchFilePaths = exports.CodexRolloutParser = exports.parseDbPartData = exports.parseDbMessageData = exports.convertOpenCodeMessage = exports.detectPlanModeFromText = exports.normalizeToolInput = exports.normalizeToolName = exports.TRUNCATION_PATTERNS = exports.JsonlParser = exports.CodexProvider = exports.OpenCodeProvider = exports.ClaudeCodeProvider = exports.getAllDetectedProviders = exports.detectProvider = exports.readClaudeCodePlanFiles = exports.getPlanAnalytics = exports.writePlans = exports.getLatestPlan = exports.readPlans = exports.readLatestHandoff = exports.readHistory = exports.readNotes = exports.readDecisions = exports.readTasks = exports.getProjectSlugRaw = exports.getProjectSlug = exports.encodeWorkspacePath = exports.getGlobalDataPath = exports.getProjectDataPath = exports.getConfigDir = exports.MAX_PLANS_PER_PROJECT = exports.PLAN_SCHEMA_VERSION = exports.createEmptyTokenTotals = exports.HISTORICAL_DATA_SCHEMA_VERSION = exports.STALENESS_THRESHOLDS = exports.IMPORTANCE_DECAY_FACTORS = exports.KNOWLEDGE_NOTE_SCHEMA_VERSION = exports.DECISION_LOG_SCHEMA_VERSION = exports.normalizeTaskStatus = exports.TASK_PERSISTENCE_SCHEMA_VERSION = void 0;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.scopePeakHoursToSessionProvider = exports.isClaudeCodeSessionProvider = exports.fetchPeakHoursStatus = exports.createPeakHoursNotApplicableState = exports.fetchOpenAIStatus = exports.fetchProviderStatus = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = void 0;
|
|
7
|
+
exports.clearHighlightCache = exports.highlightEvent = exports.formatSessionJson = exports.formatSessionMarkdown = exports.formatSessionText = exports.classifyNoise = exports.shouldMergeWithPrevious = exports.classifyFollowEvent = exports.classifyMessage = exports.getSoftNoiseReason = exports.isHardNoiseFollowEvent = exports.isHardNoise = exports.formatToolSummary = exports.formatTokenCount = exports.formatDurationMs = exports.createJsonlTail = exports.toFollowEvents = exports.createWatcher = exports.parseChangelog = exports.extractProposedPlanShared = exports.parsePlanMarkdownShared = exports.PlanExtractor = exports.segmentAssistantTurn = exports.reasoningSummary = exports.isAssistantTurnSubagentTool = exports.extractTurnSubagents = exports.assistantTurnEventsFromSessionEvents = exports.readSessionContextSnapshot = exports.createSessionContextProjector = exports.calculateSessionContextPressure = exports.buildSessionContextSnapshot = exports.composeContext = exports.FilterEngine = exports.searchSessions = exports.CodexDatabase = exports.OpenCodeDatabase = exports.discoverDebugLogs = exports.collapseDuplicates = exports.filterByLevel = exports.parseDebugLog = exports.scanSubagentTraces = exports.findAllSessionsWithWorktrees = exports.discoverWorktreeSiblings = exports.resolveWorktreeMainRepo = exports.getAllClaudeProjectFolders = exports.decodeEncodedPath = exports.getMostRecentlyActiveSessionDir = exports.findSubdirectorySessionDirs = exports.findSessionsInDirectory = exports.findAllClaudeSessions = void 0;
|
|
8
|
+
exports.getCodexExecutionEnv = exports.resolveSidekickCodexHome = exports.getActiveCodexAccount = exports.listCodexAccounts = exports.getSystemCodexHome = exports.getCodexMonitoringHomes = exports.getCodexProfileHome = exports.getCodexProfilesDir = exports.getActiveAccountStatus = exports.removeSavedAccountProfile = exports.replaceSavedAccountProfiles = exports.setActiveSavedAccount = exports.upsertSavedAccountProfile = exports.getActiveSavedAccount = exports.listSavedAccountProfiles = exports.writeSavedAccountRegistry = exports.readSavedAccountRegistry = exports.getAccountsDir = exports.isMultiAccountEnabled = exports.getActiveAccount = exports.listAccounts = exports.removeAccount = exports.switchToAccount = exports.addCurrentAccount = exports.readActiveClaudeAccount = exports.writeAccountRegistry = exports.readAccountRegistry = exports.ensureDefaultAccounts = exports.readClaudeMaxAccessTokenSync = exports.readClaudeMaxCredentials = exports.writeActiveCredentials = exports.readActiveCredentials = exports.openInBrowser = exports.parseTranscriptFromEvents = exports.parseTranscript = exports.generateHtmlReport = exports.PatternExtractor = exports.HeatmapTracker = exports.FrequencyTracker = exports.getSnapshotPath = exports.isSnapshotValid = exports.deleteSnapshot = exports.loadSnapshot = exports.saveSnapshot = exports.parseTodoDependencies = exports.EventAggregator = exports.getRandomPhrase = exports.PHRASE_CATEGORIES = exports.ALL_PHRASES = exports.HIGHLIGHT_CSS = void 0;
|
|
9
|
+
exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = exports.extractToolCalls = exports.extractToolCall = exports.extractTokenUsage = exports.LITELLM_CATALOG_URL = exports.normalizeLiteLlmCatalog = exports.hydratePricingCatalog = exports.formatCost = exports.sortModelIds = exports.compareModelIds = exports.getModelDisplayInfo = exports.shortModelName = exports.mergeCostSources = exports.calculateCostWithProvenance = exports.calculateCostWithPricing = exports.calculateCost = exports.getModelInfo = exports.getModelPricing = exports.parseModelId = exports.DEFAULT_CONTEXT_WINDOW = exports.getModelContextWindowSize = exports.MultiProviderQuotaService = exports.CodexQuotaWatcher = exports.resolveCodexQuotaFromLocalSources = exports.resolveCodexQuota = exports.readLatestCodexQuotaFromRollouts = exports.quotaFromCodexRateLimits = exports.fetchCodexQuotaFromApi = exports.getWorkspaceIdFromPath = exports.pruneQuotaHistory = exports.readQuotaHistoryDailyBuckets = exports.readQuotaHistoryRange = exports.appendQuotaHistorySample = exports.writeQuotaSnapshot = exports.readQuotaSnapshot = exports.QuotaPoller = exports.describeQuotaFailure = exports.fetchQuota = exports.removeCodexAccount = exports.switchToCodexAccount = exports.finalizeCodexAccount = exports.prepareCodexAccount = void 0;
|
|
10
|
+
exports.scopePeakHoursToSessionProvider = exports.isClaudeCodeSessionProvider = exports.fetchPeakHoursStatus = exports.createPeakHoursNotApplicableState = exports.fetchOpenAIStatus = exports.fetchProviderStatus = exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaSourceSchema = void 0;
|
|
11
11
|
var taskPersistence_1 = require("./types/taskPersistence");
|
|
12
12
|
Object.defineProperty(exports, "TASK_PERSISTENCE_SCHEMA_VERSION", { enumerable: true, get: function () { return taskPersistence_1.TASK_PERSISTENCE_SCHEMA_VERSION; } });
|
|
13
13
|
Object.defineProperty(exports, "normalizeTaskStatus", { enumerable: true, get: function () { return taskPersistence_1.normalizeTaskStatus; } });
|
|
@@ -124,6 +124,13 @@ Object.defineProperty(exports, "buildSessionContextSnapshot", { enumerable: true
|
|
|
124
124
|
Object.defineProperty(exports, "calculateSessionContextPressure", { enumerable: true, get: function () { return sessionContext_1.calculateSessionContextPressure; } });
|
|
125
125
|
Object.defineProperty(exports, "createSessionContextProjector", { enumerable: true, get: function () { return sessionContext_1.createSessionContextProjector; } });
|
|
126
126
|
Object.defineProperty(exports, "readSessionContextSnapshot", { enumerable: true, get: function () { return sessionContext_1.readSessionContextSnapshot; } });
|
|
127
|
+
// Assistant turn projection
|
|
128
|
+
var assistantTurn_1 = require("./turns/assistantTurn");
|
|
129
|
+
Object.defineProperty(exports, "assistantTurnEventsFromSessionEvents", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventsFromSessionEvents; } });
|
|
130
|
+
Object.defineProperty(exports, "extractTurnSubagents", { enumerable: true, get: function () { return assistantTurn_1.extractTurnSubagents; } });
|
|
131
|
+
Object.defineProperty(exports, "isAssistantTurnSubagentTool", { enumerable: true, get: function () { return assistantTurn_1.isAssistantTurnSubagentTool; } });
|
|
132
|
+
Object.defineProperty(exports, "reasoningSummary", { enumerable: true, get: function () { return assistantTurn_1.reasoningSummary; } });
|
|
133
|
+
Object.defineProperty(exports, "segmentAssistantTurn", { enumerable: true, get: function () { return assistantTurn_1.segmentAssistantTurn; } });
|
|
127
134
|
// Plan Extraction
|
|
128
135
|
var planExtractor_1 = require("./parsers/planExtractor");
|
|
129
136
|
Object.defineProperty(exports, "PlanExtractor", { enumerable: true, get: function () { return planExtractor_1.PlanExtractor; } });
|
|
@@ -320,6 +327,17 @@ Object.defineProperty(exports, "quotaHistoryDailyBucketSchema", { enumerable: tr
|
|
|
320
327
|
var accountStatus_2 = require("./schemas/accountStatus");
|
|
321
328
|
Object.defineProperty(exports, "activeProviderAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_2.activeProviderAccountStatusSchema; } });
|
|
322
329
|
Object.defineProperty(exports, "activeAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_2.activeAccountStatusSchema; } });
|
|
330
|
+
var assistantTurn_2 = require("./schemas/assistantTurn");
|
|
331
|
+
Object.defineProperty(exports, "assistantTurnEventSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnEventSchema; } });
|
|
332
|
+
Object.defineProperty(exports, "assistantTurnEventTypeSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnEventTypeSchema; } });
|
|
333
|
+
Object.defineProperty(exports, "assistantTurnNarrationStepSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnNarrationStepSchema; } });
|
|
334
|
+
Object.defineProperty(exports, "assistantTurnProcessSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnProcessSchema; } });
|
|
335
|
+
Object.defineProperty(exports, "assistantTurnProcessStepSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnProcessStepSchema; } });
|
|
336
|
+
Object.defineProperty(exports, "assistantTurnProjectionSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnProjectionSchema; } });
|
|
337
|
+
Object.defineProperty(exports, "assistantTurnSubagentSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnSubagentSchema; } });
|
|
338
|
+
Object.defineProperty(exports, "assistantTurnSubagentStatusSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnSubagentStatusSchema; } });
|
|
339
|
+
Object.defineProperty(exports, "assistantTurnToolGroupStepSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnToolGroupStepSchema; } });
|
|
340
|
+
Object.defineProperty(exports, "assistantTurnToolRefSchema", { enumerable: true, get: function () { return assistantTurn_2.assistantTurnToolRefSchema; } });
|
|
323
341
|
// Provider Status
|
|
324
342
|
var providerStatus_1 = require("./providerStatus");
|
|
325
343
|
Object.defineProperty(exports, "fetchProviderStatus", { enumerable: true, get: function () { return providerStatus_1.fetchProviderStatus; } });
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for browser-safe assistant turn projections.
|
|
3
|
+
*
|
|
4
|
+
* These schemas mirror `turns/assistantTurn.ts` and validate the compact
|
|
5
|
+
* process/answer shape used at UI and IPC boundaries.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export declare const assistantTurnEventTypeSchema: z.ZodEnum<{
|
|
9
|
+
status: "status";
|
|
10
|
+
tool_use: "tool_use";
|
|
11
|
+
tool_result: "tool_result";
|
|
12
|
+
error: "error";
|
|
13
|
+
text: "text";
|
|
14
|
+
progress: "progress";
|
|
15
|
+
thinking: "thinking";
|
|
16
|
+
delta: "delta";
|
|
17
|
+
}>;
|
|
18
|
+
export declare const assistantTurnEventSchema: z.ZodObject<{
|
|
19
|
+
eventType: z.ZodEnum<{
|
|
20
|
+
status: "status";
|
|
21
|
+
tool_use: "tool_use";
|
|
22
|
+
tool_result: "tool_result";
|
|
23
|
+
error: "error";
|
|
24
|
+
text: "text";
|
|
25
|
+
progress: "progress";
|
|
26
|
+
thinking: "thinking";
|
|
27
|
+
delta: "delta";
|
|
28
|
+
}>;
|
|
29
|
+
content: z.ZodString;
|
|
30
|
+
deltaKind: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
text: "text";
|
|
32
|
+
thinking: "thinking";
|
|
33
|
+
tool_input: "tool_input";
|
|
34
|
+
}>>;
|
|
35
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
36
|
+
toolInput: z.ZodOptional<z.ZodUnknown>;
|
|
37
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export declare const assistantTurnToolRefSchema: z.ZodObject<{
|
|
40
|
+
toolName: z.ZodString;
|
|
41
|
+
toolInput: z.ZodOptional<z.ZodString>;
|
|
42
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export declare const assistantTurnNarrationStepSchema: z.ZodObject<{
|
|
45
|
+
kind: z.ZodLiteral<"narration">;
|
|
46
|
+
text: z.ZodString;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export declare const assistantTurnToolGroupStepSchema: z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"toolGroup">;
|
|
50
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
51
|
+
toolName: z.ZodString;
|
|
52
|
+
toolInput: z.ZodOptional<z.ZodString>;
|
|
53
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$strip>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const assistantTurnProcessStepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"narration">;
|
|
58
|
+
text: z.ZodString;
|
|
59
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"toolGroup">;
|
|
61
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
62
|
+
toolName: z.ZodString;
|
|
63
|
+
toolInput: z.ZodOptional<z.ZodString>;
|
|
64
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
}, z.core.$strip>], "kind">;
|
|
67
|
+
export declare const assistantTurnProcessSchema: z.ZodObject<{
|
|
68
|
+
steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
69
|
+
kind: z.ZodLiteral<"narration">;
|
|
70
|
+
text: z.ZodString;
|
|
71
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
72
|
+
kind: z.ZodLiteral<"toolGroup">;
|
|
73
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
74
|
+
toolName: z.ZodString;
|
|
75
|
+
toolInput: z.ZodOptional<z.ZodString>;
|
|
76
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
}, z.core.$strip>], "kind">>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
export declare const assistantTurnSubagentStatusSchema: z.ZodEnum<{
|
|
81
|
+
completed: "completed";
|
|
82
|
+
failed: "failed";
|
|
83
|
+
running: "running";
|
|
84
|
+
}>;
|
|
85
|
+
export declare const assistantTurnSubagentSchema: z.ZodObject<{
|
|
86
|
+
id: z.ZodString;
|
|
87
|
+
label: z.ZodString;
|
|
88
|
+
agentType: z.ZodOptional<z.ZodString>;
|
|
89
|
+
status: z.ZodEnum<{
|
|
90
|
+
completed: "completed";
|
|
91
|
+
failed: "failed";
|
|
92
|
+
running: "running";
|
|
93
|
+
}>;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
export declare const assistantTurnProjectionSchema: z.ZodObject<{
|
|
96
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
97
|
+
answer: z.ZodString;
|
|
98
|
+
reasoning: z.ZodString;
|
|
99
|
+
reasoningBlocks: z.ZodArray<z.ZodString>;
|
|
100
|
+
process: z.ZodObject<{
|
|
101
|
+
steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
102
|
+
kind: z.ZodLiteral<"narration">;
|
|
103
|
+
text: z.ZodString;
|
|
104
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
105
|
+
kind: z.ZodLiteral<"toolGroup">;
|
|
106
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
107
|
+
toolName: z.ZodString;
|
|
108
|
+
toolInput: z.ZodOptional<z.ZodString>;
|
|
109
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strip>>;
|
|
111
|
+
}, z.core.$strip>], "kind">>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
subagents: z.ZodArray<z.ZodObject<{
|
|
114
|
+
id: z.ZodString;
|
|
115
|
+
label: z.ZodString;
|
|
116
|
+
agentType: z.ZodOptional<z.ZodString>;
|
|
117
|
+
status: z.ZodEnum<{
|
|
118
|
+
completed: "completed";
|
|
119
|
+
failed: "failed";
|
|
120
|
+
running: "running";
|
|
121
|
+
}>;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schemas for browser-safe assistant turn projections.
|
|
4
|
+
*
|
|
5
|
+
* These schemas mirror `turns/assistantTurn.ts` and validate the compact
|
|
6
|
+
* process/answer shape used at UI and IPC boundaries.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.assistantTurnProjectionSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnProcessSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnToolRefSchema = exports.assistantTurnEventSchema = exports.assistantTurnEventTypeSchema = void 0;
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
exports.assistantTurnEventTypeSchema = zod_1.z.enum([
|
|
12
|
+
'text',
|
|
13
|
+
'thinking',
|
|
14
|
+
'tool_use',
|
|
15
|
+
'tool_result',
|
|
16
|
+
'status',
|
|
17
|
+
'error',
|
|
18
|
+
'delta',
|
|
19
|
+
'progress',
|
|
20
|
+
]);
|
|
21
|
+
exports.assistantTurnEventSchema = zod_1.z.object({
|
|
22
|
+
eventType: exports.assistantTurnEventTypeSchema,
|
|
23
|
+
content: zod_1.z.string(),
|
|
24
|
+
deltaKind: zod_1.z.enum(['text', 'thinking', 'tool_input']).optional(),
|
|
25
|
+
toolName: zod_1.z.string().optional(),
|
|
26
|
+
toolInput: zod_1.z.unknown().optional(),
|
|
27
|
+
toolUseId: zod_1.z.string().optional(),
|
|
28
|
+
});
|
|
29
|
+
exports.assistantTurnToolRefSchema = zod_1.z.object({
|
|
30
|
+
toolName: zod_1.z.string(),
|
|
31
|
+
toolInput: zod_1.z.string().optional(),
|
|
32
|
+
toolUseId: zod_1.z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
exports.assistantTurnNarrationStepSchema = zod_1.z.object({
|
|
35
|
+
kind: zod_1.z.literal('narration'),
|
|
36
|
+
text: zod_1.z.string(),
|
|
37
|
+
});
|
|
38
|
+
exports.assistantTurnToolGroupStepSchema = zod_1.z.object({
|
|
39
|
+
kind: zod_1.z.literal('toolGroup'),
|
|
40
|
+
tools: zod_1.z.array(exports.assistantTurnToolRefSchema),
|
|
41
|
+
});
|
|
42
|
+
exports.assistantTurnProcessStepSchema = zod_1.z.discriminatedUnion('kind', [
|
|
43
|
+
exports.assistantTurnNarrationStepSchema,
|
|
44
|
+
exports.assistantTurnToolGroupStepSchema,
|
|
45
|
+
]);
|
|
46
|
+
exports.assistantTurnProcessSchema = zod_1.z.object({
|
|
47
|
+
steps: zod_1.z.array(exports.assistantTurnProcessStepSchema),
|
|
48
|
+
});
|
|
49
|
+
exports.assistantTurnSubagentStatusSchema = zod_1.z.enum([
|
|
50
|
+
'running',
|
|
51
|
+
'completed',
|
|
52
|
+
'failed',
|
|
53
|
+
]);
|
|
54
|
+
exports.assistantTurnSubagentSchema = zod_1.z.object({
|
|
55
|
+
id: zod_1.z.string(),
|
|
56
|
+
label: zod_1.z.string(),
|
|
57
|
+
agentType: zod_1.z.string().optional(),
|
|
58
|
+
status: exports.assistantTurnSubagentStatusSchema,
|
|
59
|
+
});
|
|
60
|
+
exports.assistantTurnProjectionSchema = zod_1.z.object({
|
|
61
|
+
schemaVersion: zod_1.z.literal(1),
|
|
62
|
+
answer: zod_1.z.string(),
|
|
63
|
+
reasoning: zod_1.z.string(),
|
|
64
|
+
reasoningBlocks: zod_1.z.array(zod_1.z.string()),
|
|
65
|
+
process: exports.assistantTurnProcessSchema,
|
|
66
|
+
subagents: zod_1.z.array(exports.assistantTurnSubagentSchema),
|
|
67
|
+
});
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Schemas entry (`sidekick-shared/schemas`).
|
|
3
3
|
*
|
|
4
4
|
* Pure zod runtime validation for the data shapes that cross process/IPC
|
|
5
|
-
* boundaries: session events, quota state, quota history, account status
|
|
6
|
-
* No node:fs / node:path — safe to bundle
|
|
7
|
-
* enough that importing it does not drag in
|
|
5
|
+
* boundaries: session events, quota state, quota history, account status,
|
|
6
|
+
* and assistant turn projections. No node:fs / node:path — safe to bundle
|
|
7
|
+
* for browser runtimes, and lean enough that importing it does not drag in
|
|
8
|
+
* the rest of the library.
|
|
8
9
|
*
|
|
9
10
|
* The mirrored TypeScript interfaces are re-exported as types so this
|
|
10
11
|
* subpath is self-sufficient for boundary-validation modules.
|
|
@@ -20,3 +21,5 @@ export { quotaHistoryRuntimeProviderSchema, quotaHistorySampleSchema, quotaHisto
|
|
|
20
21
|
export type { QuotaHistoryRuntimeProvider, QuotaHistorySample, QuotaHistoryDailyBucket, } from '../quotaHistory';
|
|
21
22
|
export { activeProviderAccountStatusSchema, activeAccountStatusSchema, } from './accountStatus';
|
|
22
23
|
export type { ActiveProviderAccountStatus, ActiveAccountStatus, } from '../accountStatus';
|
|
24
|
+
export { assistantTurnEventSchema, assistantTurnEventTypeSchema, assistantTurnNarrationStepSchema, assistantTurnProcessSchema, assistantTurnProcessStepSchema, assistantTurnProjectionSchema, assistantTurnSubagentSchema, assistantTurnSubagentStatusSchema, assistantTurnToolGroupStepSchema, assistantTurnToolRefSchema, } from './assistantTurn';
|
|
25
|
+
export type { AssistantTurnEvent, AssistantTurnEventType, AssistantTurnProcess, AssistantTurnProcessStep, AssistantTurnProjection, AssistantTurnSubagent, AssistantTurnSubagentStatus, AssistantTurnToolRef, } from '../turns/assistantTurn';
|
package/dist/schemas/index.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
* Schemas entry (`sidekick-shared/schemas`).
|
|
4
4
|
*
|
|
5
5
|
* Pure zod runtime validation for the data shapes that cross process/IPC
|
|
6
|
-
* boundaries: session events, quota state, quota history, account status
|
|
7
|
-
* No node:fs / node:path — safe to bundle
|
|
8
|
-
* enough that importing it does not drag in
|
|
6
|
+
* boundaries: session events, quota state, quota history, account status,
|
|
7
|
+
* and assistant turn projections. No node:fs / node:path — safe to bundle
|
|
8
|
+
* for browser runtimes, and lean enough that importing it does not drag in
|
|
9
|
+
* the rest of the library.
|
|
9
10
|
*
|
|
10
11
|
* The mirrored TypeScript interfaces are re-exported as types so this
|
|
11
12
|
* subpath is self-sufficient for boundary-validation modules.
|
|
12
13
|
*/
|
|
13
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = void 0;
|
|
15
|
+
exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = void 0;
|
|
15
16
|
var sessionEvent_1 = require("./sessionEvent");
|
|
16
17
|
Object.defineProperty(exports, "messageUsageSchema", { enumerable: true, get: function () { return sessionEvent_1.messageUsageSchema; } });
|
|
17
18
|
Object.defineProperty(exports, "sessionMessageSchema", { enumerable: true, get: function () { return sessionEvent_1.sessionMessageSchema; } });
|
|
@@ -38,3 +39,14 @@ Object.defineProperty(exports, "quotaHistoryDailyBucketSchema", { enumerable: tr
|
|
|
38
39
|
var accountStatus_1 = require("./accountStatus");
|
|
39
40
|
Object.defineProperty(exports, "activeProviderAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_1.activeProviderAccountStatusSchema; } });
|
|
40
41
|
Object.defineProperty(exports, "activeAccountStatusSchema", { enumerable: true, get: function () { return accountStatus_1.activeAccountStatusSchema; } });
|
|
42
|
+
var assistantTurn_1 = require("./assistantTurn");
|
|
43
|
+
Object.defineProperty(exports, "assistantTurnEventSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventSchema; } });
|
|
44
|
+
Object.defineProperty(exports, "assistantTurnEventTypeSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnEventTypeSchema; } });
|
|
45
|
+
Object.defineProperty(exports, "assistantTurnNarrationStepSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnNarrationStepSchema; } });
|
|
46
|
+
Object.defineProperty(exports, "assistantTurnProcessSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnProcessSchema; } });
|
|
47
|
+
Object.defineProperty(exports, "assistantTurnProcessStepSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnProcessStepSchema; } });
|
|
48
|
+
Object.defineProperty(exports, "assistantTurnProjectionSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnProjectionSchema; } });
|
|
49
|
+
Object.defineProperty(exports, "assistantTurnSubagentSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnSubagentSchema; } });
|
|
50
|
+
Object.defineProperty(exports, "assistantTurnSubagentStatusSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnSubagentStatusSchema; } });
|
|
51
|
+
Object.defineProperty(exports, "assistantTurnToolGroupStepSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnToolGroupStepSchema; } });
|
|
52
|
+
Object.defineProperty(exports, "assistantTurnToolRefSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnToolRefSchema; } });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SessionEvent } from '../types/sessionEvent';
|
|
2
|
+
export type AssistantTurnEventType = 'text' | 'thinking' | 'tool_use' | 'tool_result' | 'status' | 'error' | 'delta' | 'progress';
|
|
3
|
+
export interface AssistantTurnEvent {
|
|
4
|
+
eventType: AssistantTurnEventType;
|
|
5
|
+
content: string;
|
|
6
|
+
deltaKind?: 'text' | 'thinking' | 'tool_input';
|
|
7
|
+
toolName?: string;
|
|
8
|
+
toolInput?: unknown;
|
|
9
|
+
toolUseId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AssistantTurnToolRef {
|
|
12
|
+
toolName: string;
|
|
13
|
+
toolInput?: string;
|
|
14
|
+
toolUseId?: string;
|
|
15
|
+
}
|
|
16
|
+
export type AssistantTurnProcessStep = {
|
|
17
|
+
kind: 'narration';
|
|
18
|
+
text: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'toolGroup';
|
|
21
|
+
tools: AssistantTurnToolRef[];
|
|
22
|
+
};
|
|
23
|
+
export interface AssistantTurnProcess {
|
|
24
|
+
steps: AssistantTurnProcessStep[];
|
|
25
|
+
}
|
|
26
|
+
export type AssistantTurnSubagentStatus = 'running' | 'completed' | 'failed';
|
|
27
|
+
export interface AssistantTurnSubagent {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
agentType?: string;
|
|
31
|
+
status: AssistantTurnSubagentStatus;
|
|
32
|
+
}
|
|
33
|
+
export interface AssistantTurnProjection {
|
|
34
|
+
schemaVersion: 1;
|
|
35
|
+
answer: string;
|
|
36
|
+
reasoning: string;
|
|
37
|
+
reasoningBlocks: string[];
|
|
38
|
+
process: AssistantTurnProcess;
|
|
39
|
+
subagents: AssistantTurnSubagent[];
|
|
40
|
+
}
|
|
41
|
+
export interface SegmentAssistantTurnOptions {
|
|
42
|
+
maxNarrationChars?: number;
|
|
43
|
+
maxReasoningChars?: number;
|
|
44
|
+
maxProcessSteps?: number;
|
|
45
|
+
maxReasoningBlocks?: number;
|
|
46
|
+
toolInputMaxChars?: number;
|
|
47
|
+
subagentStatus?: AssistantTurnSubagentStatus;
|
|
48
|
+
sanitizeToolInput?: (tool: {
|
|
49
|
+
toolName: string;
|
|
50
|
+
toolInput: unknown;
|
|
51
|
+
toolUseId?: string;
|
|
52
|
+
}) => string | undefined;
|
|
53
|
+
}
|
|
54
|
+
export interface ExtractTurnSubagentsOptions {
|
|
55
|
+
status: AssistantTurnSubagentStatus;
|
|
56
|
+
}
|
|
57
|
+
export interface ReasoningSummary {
|
|
58
|
+
title: string | null;
|
|
59
|
+
body: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function reasoningSummary(text: string): ReasoningSummary;
|
|
62
|
+
export declare function isAssistantTurnSubagentTool(toolName: string | undefined): boolean;
|
|
63
|
+
export declare function segmentAssistantTurn(events: readonly AssistantTurnEvent[], options?: SegmentAssistantTurnOptions): AssistantTurnProjection;
|
|
64
|
+
export declare function assistantTurnEventsFromSessionEvents(events: readonly SessionEvent[]): AssistantTurnEvent[];
|
|
65
|
+
export declare function extractTurnSubagents(tools: ReadonlyArray<{
|
|
66
|
+
toolName?: string;
|
|
67
|
+
toolInput?: unknown;
|
|
68
|
+
toolUseId?: string;
|
|
69
|
+
}>, options: ExtractTurnSubagentsOptions): AssistantTurnSubagent[];
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reasoningSummary = reasoningSummary;
|
|
4
|
+
exports.isAssistantTurnSubagentTool = isAssistantTurnSubagentTool;
|
|
5
|
+
exports.segmentAssistantTurn = segmentAssistantTurn;
|
|
6
|
+
exports.assistantTurnEventsFromSessionEvents = assistantTurnEventsFromSessionEvents;
|
|
7
|
+
exports.extractTurnSubagents = extractTurnSubagents;
|
|
8
|
+
const toolSummary_1 = require("../formatters/toolSummary");
|
|
9
|
+
const DEFAULT_NARRATION_CHARS = 4000;
|
|
10
|
+
const DEFAULT_REASONING_CHARS = 8000;
|
|
11
|
+
const DEFAULT_PROCESS_STEPS = 60;
|
|
12
|
+
const DEFAULT_REASONING_BLOCKS = 24;
|
|
13
|
+
const DEFAULT_TOOL_INPUT_CHARS = 200;
|
|
14
|
+
const SUBAGENT_TOOL_NAMES = new Set(['Task']);
|
|
15
|
+
const LABEL_MAX = 80;
|
|
16
|
+
const TITLE_RE = /^\s*\*\*([^*\n]+)\*\*[ \t]*(?:\n+([\s\S]*))?$/;
|
|
17
|
+
const TITLE_MAX = 100;
|
|
18
|
+
function reasoningSummary(text) {
|
|
19
|
+
const normalized = text.replace(/\r\n/g, '\n');
|
|
20
|
+
const trimmed = normalized.trim();
|
|
21
|
+
if (trimmed === '')
|
|
22
|
+
return { title: null, body: '' };
|
|
23
|
+
const match = TITLE_RE.exec(normalized);
|
|
24
|
+
if (match) {
|
|
25
|
+
const title = match[1].trim();
|
|
26
|
+
if (title !== '' && title.length <= TITLE_MAX) {
|
|
27
|
+
return { title, body: (match[2] ?? '').trim() };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { title: null, body: trimmed };
|
|
31
|
+
}
|
|
32
|
+
function isAssistantTurnSubagentTool(toolName) {
|
|
33
|
+
return toolName != null && SUBAGENT_TOOL_NAMES.has(toolName);
|
|
34
|
+
}
|
|
35
|
+
function segmentAssistantTurn(events, options = {}) {
|
|
36
|
+
const maxNarrationChars = options.maxNarrationChars ?? DEFAULT_NARRATION_CHARS;
|
|
37
|
+
const maxReasoningChars = options.maxReasoningChars ?? DEFAULT_REASONING_CHARS;
|
|
38
|
+
const maxProcessSteps = options.maxProcessSteps ?? DEFAULT_PROCESS_STEPS;
|
|
39
|
+
const maxReasoningBlocks = options.maxReasoningBlocks ?? DEFAULT_REASONING_BLOCKS;
|
|
40
|
+
const subagentStatus = options.subagentStatus ?? 'completed';
|
|
41
|
+
const reasoningParts = [];
|
|
42
|
+
const steps = [];
|
|
43
|
+
let textBuffer = [];
|
|
44
|
+
let toolGroup = null;
|
|
45
|
+
function closeToolGroup() {
|
|
46
|
+
if (toolGroup != null && toolGroup.tools.length > 0) {
|
|
47
|
+
steps.push(toolGroup);
|
|
48
|
+
}
|
|
49
|
+
toolGroup = null;
|
|
50
|
+
}
|
|
51
|
+
function sealTextAsNarration() {
|
|
52
|
+
const text = joinText(textBuffer);
|
|
53
|
+
if (text !== '') {
|
|
54
|
+
steps.push({ kind: 'narration', text: capText(text, maxNarrationChars) });
|
|
55
|
+
}
|
|
56
|
+
textBuffer = [];
|
|
57
|
+
}
|
|
58
|
+
for (const event of events) {
|
|
59
|
+
switch (event.eventType) {
|
|
60
|
+
case 'text': {
|
|
61
|
+
if (event.content.trim() === '')
|
|
62
|
+
break;
|
|
63
|
+
closeToolGroup();
|
|
64
|
+
textBuffer.push(event.content);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'thinking': {
|
|
68
|
+
if (event.content.trim() === '')
|
|
69
|
+
break;
|
|
70
|
+
sealTextAsNarration();
|
|
71
|
+
closeToolGroup();
|
|
72
|
+
reasoningParts.push(event.content);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'tool_use': {
|
|
76
|
+
sealTextAsNarration();
|
|
77
|
+
if (toolGroup == null)
|
|
78
|
+
toolGroup = { kind: 'toolGroup', tools: [] };
|
|
79
|
+
const toolName = event.toolName ?? 'tool';
|
|
80
|
+
const tool = { toolName };
|
|
81
|
+
const toolInput = formatTurnToolInput(toolName, event.toolInput, event.toolUseId, options);
|
|
82
|
+
if (toolInput != null && toolInput !== '')
|
|
83
|
+
tool.toolInput = toolInput;
|
|
84
|
+
if (event.toolUseId != null && event.toolUseId !== '')
|
|
85
|
+
tool.toolUseId = event.toolUseId;
|
|
86
|
+
toolGroup.tools.push(tool);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const answer = joinText(textBuffer);
|
|
94
|
+
closeToolGroup();
|
|
95
|
+
const reasoningBlocks = capReasoningBlocks(reasoningParts
|
|
96
|
+
.filter((part) => part.trim() !== '')
|
|
97
|
+
.map((part) => capText(part, maxReasoningChars)), maxReasoningBlocks);
|
|
98
|
+
const process = { steps: capProcessSteps(steps, maxProcessSteps) };
|
|
99
|
+
return {
|
|
100
|
+
schemaVersion: 1,
|
|
101
|
+
answer,
|
|
102
|
+
reasoning: capText(joinText(reasoningParts), maxReasoningChars),
|
|
103
|
+
reasoningBlocks,
|
|
104
|
+
process,
|
|
105
|
+
subagents: extractTurnSubagents(flattenProcessTools(process), { status: subagentStatus }),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function assistantTurnEventsFromSessionEvents(events) {
|
|
109
|
+
const result = [];
|
|
110
|
+
for (const event of events) {
|
|
111
|
+
if (event.type === 'assistant') {
|
|
112
|
+
appendMessageContentEvents(result, event.message.content);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (event.type === 'tool_use' && event.tool != null) {
|
|
116
|
+
result.push({
|
|
117
|
+
eventType: 'tool_use',
|
|
118
|
+
content: '',
|
|
119
|
+
toolName: event.tool.name,
|
|
120
|
+
toolInput: event.tool.input,
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (event.type === 'tool_result') {
|
|
125
|
+
result.push({
|
|
126
|
+
eventType: 'tool_result',
|
|
127
|
+
content: stringifyValue(event.result?.output),
|
|
128
|
+
toolUseId: event.result?.tool_use_id,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
function extractTurnSubagents(tools, options) {
|
|
135
|
+
const result = [];
|
|
136
|
+
for (const tool of tools) {
|
|
137
|
+
if (!isAssistantTurnSubagentTool(tool.toolName))
|
|
138
|
+
continue;
|
|
139
|
+
const input = parseSubagentInput(tool.toolInput);
|
|
140
|
+
const index = result.length;
|
|
141
|
+
const label = capLabel(input.description ?? input.agentType ?? `Agent ${index + 1}`);
|
|
142
|
+
const ref = {
|
|
143
|
+
id: tool.toolUseId && tool.toolUseId !== '' ? tool.toolUseId : `subagent-${index}`,
|
|
144
|
+
label,
|
|
145
|
+
status: options.status,
|
|
146
|
+
};
|
|
147
|
+
if (input.agentType != null)
|
|
148
|
+
ref.agentType = input.agentType;
|
|
149
|
+
result.push(ref);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function appendMessageContentEvents(result, content) {
|
|
154
|
+
if (typeof content === 'string') {
|
|
155
|
+
if (content !== '')
|
|
156
|
+
result.push({ eventType: 'text', content });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!Array.isArray(content))
|
|
160
|
+
return;
|
|
161
|
+
for (const block of content) {
|
|
162
|
+
if (!isRecord(block))
|
|
163
|
+
continue;
|
|
164
|
+
const type = stringValue(block.type);
|
|
165
|
+
if (type === 'text') {
|
|
166
|
+
const text = stringValue(block.text) ?? stringValue(block.content);
|
|
167
|
+
if (text != null)
|
|
168
|
+
result.push({ eventType: 'text', content: text });
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (type === 'thinking' || type === 'reasoning') {
|
|
172
|
+
const text = stringValue(block.thinking) ?? stringValue(block.text) ?? stringValue(block.content);
|
|
173
|
+
if (text != null)
|
|
174
|
+
result.push({ eventType: 'thinking', content: text });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (type === 'tool_use') {
|
|
178
|
+
const toolName = stringValue(block.name) ?? 'tool';
|
|
179
|
+
const event = {
|
|
180
|
+
eventType: 'tool_use',
|
|
181
|
+
content: '',
|
|
182
|
+
toolName,
|
|
183
|
+
toolInput: block.input,
|
|
184
|
+
};
|
|
185
|
+
const toolUseId = stringValue(block.id);
|
|
186
|
+
if (toolUseId != null)
|
|
187
|
+
event.toolUseId = toolUseId;
|
|
188
|
+
result.push(event);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (type === 'tool_result') {
|
|
192
|
+
const event = {
|
|
193
|
+
eventType: 'tool_result',
|
|
194
|
+
content: stringifyValue(block.content),
|
|
195
|
+
};
|
|
196
|
+
const toolUseId = stringValue(block.tool_use_id);
|
|
197
|
+
if (toolUseId != null)
|
|
198
|
+
event.toolUseId = toolUseId;
|
|
199
|
+
result.push(event);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function formatTurnToolInput(toolName, toolInput, toolUseId, options) {
|
|
204
|
+
if (options.sanitizeToolInput != null) {
|
|
205
|
+
return options.sanitizeToolInput({ toolName, toolInput, toolUseId });
|
|
206
|
+
}
|
|
207
|
+
if (toolInput == null)
|
|
208
|
+
return undefined;
|
|
209
|
+
const maxChars = options.toolInputMaxChars ?? DEFAULT_TOOL_INPUT_CHARS;
|
|
210
|
+
if (isAssistantTurnSubagentTool(toolName)) {
|
|
211
|
+
const input = parseSubagentInput(toolInput);
|
|
212
|
+
const projection = {};
|
|
213
|
+
if (input.agentType != null)
|
|
214
|
+
projection.subagent_type = (0, toolSummary_1.truncate)(input.agentType, LABEL_MAX);
|
|
215
|
+
if (input.description != null)
|
|
216
|
+
projection.description = (0, toolSummary_1.truncate)(input.description, maxChars);
|
|
217
|
+
return JSON.stringify(projection);
|
|
218
|
+
}
|
|
219
|
+
const record = coerceRecord(toolInput);
|
|
220
|
+
if (record != null) {
|
|
221
|
+
const summary = (0, toolSummary_1.formatToolSummary)(toolName, record);
|
|
222
|
+
return summary === '' ? undefined : (0, toolSummary_1.truncate)(summary, maxChars);
|
|
223
|
+
}
|
|
224
|
+
if (typeof toolInput === 'string') {
|
|
225
|
+
return (0, toolSummary_1.truncate)(toolInput, maxChars);
|
|
226
|
+
}
|
|
227
|
+
return (0, toolSummary_1.truncate)(stringifyValue(toolInput), maxChars);
|
|
228
|
+
}
|
|
229
|
+
function flattenProcessTools(process) {
|
|
230
|
+
const result = [];
|
|
231
|
+
for (const step of process.steps) {
|
|
232
|
+
if (step.kind === 'toolGroup')
|
|
233
|
+
result.push(...step.tools);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
function capProcessSteps(steps, maxRetainedSteps) {
|
|
238
|
+
if (!Number.isFinite(maxRetainedSteps) || maxRetainedSteps < 0)
|
|
239
|
+
return [];
|
|
240
|
+
const retainedCount = Math.floor(maxRetainedSteps);
|
|
241
|
+
if (steps.length <= retainedCount)
|
|
242
|
+
return steps;
|
|
243
|
+
const kept = retainedCount > 0 ? steps.slice(steps.length - retainedCount) : [];
|
|
244
|
+
const omitted = steps.length - kept.length;
|
|
245
|
+
return [{ kind: 'narration', text: `... ${omitted} earlier process step${omitted === 1 ? '' : 's'} omitted` }, ...kept];
|
|
246
|
+
}
|
|
247
|
+
function capReasoningBlocks(blocks, maxRetainedBlocks) {
|
|
248
|
+
if (!Number.isFinite(maxRetainedBlocks) || maxRetainedBlocks < 0)
|
|
249
|
+
return [];
|
|
250
|
+
const retainedCount = Math.floor(maxRetainedBlocks);
|
|
251
|
+
if (blocks.length <= retainedCount)
|
|
252
|
+
return blocks;
|
|
253
|
+
const kept = retainedCount > 0 ? blocks.slice(0, retainedCount) : [];
|
|
254
|
+
const omitted = blocks.length - kept.length;
|
|
255
|
+
return [...kept, `... ${omitted} more reasoning block${omitted === 1 ? '' : 's'} omitted`];
|
|
256
|
+
}
|
|
257
|
+
function parseSubagentInput(input) {
|
|
258
|
+
const record = coerceRecord(input);
|
|
259
|
+
if (record == null)
|
|
260
|
+
return {};
|
|
261
|
+
const description = stringValue(record.description)?.trim();
|
|
262
|
+
const agentType = (stringValue(record.subagent_type) ?? stringValue(record.subagentType))?.trim();
|
|
263
|
+
return {
|
|
264
|
+
...(description != null && description !== '' ? { description } : {}),
|
|
265
|
+
...(agentType != null && agentType !== '' ? { agentType } : {}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function coerceRecord(value) {
|
|
269
|
+
if (isRecord(value))
|
|
270
|
+
return value;
|
|
271
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
272
|
+
return null;
|
|
273
|
+
try {
|
|
274
|
+
const parsed = JSON.parse(value);
|
|
275
|
+
return isRecord(parsed) ? parsed : null;
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function capLabel(label) {
|
|
282
|
+
return label.length <= LABEL_MAX ? label : `${label.slice(0, LABEL_MAX - 3).trimEnd()}...`;
|
|
283
|
+
}
|
|
284
|
+
function capText(text, maxChars) {
|
|
285
|
+
if (!Number.isFinite(maxChars) || maxChars < 0)
|
|
286
|
+
return '';
|
|
287
|
+
const limit = Math.floor(maxChars);
|
|
288
|
+
if (text.length <= limit)
|
|
289
|
+
return text;
|
|
290
|
+
if (limit <= 3)
|
|
291
|
+
return '.'.repeat(limit);
|
|
292
|
+
return `${text.slice(0, limit - 3).trimEnd()}...`;
|
|
293
|
+
}
|
|
294
|
+
function joinText(parts) {
|
|
295
|
+
return parts.filter((part) => part.trim() !== '').join('\n\n');
|
|
296
|
+
}
|
|
297
|
+
function stringifyValue(value) {
|
|
298
|
+
if (value == null)
|
|
299
|
+
return '';
|
|
300
|
+
if (typeof value === 'string')
|
|
301
|
+
return value;
|
|
302
|
+
try {
|
|
303
|
+
return JSON.stringify(value, null, 2);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
return String(value);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function stringValue(value) {
|
|
310
|
+
return typeof value === 'string' ? value : undefined;
|
|
311
|
+
}
|
|
312
|
+
function isRecord(value) {
|
|
313
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
314
|
+
}
|
package/package.json
CHANGED