@kortix/sdk 0.13.29 → 0.13.31
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 +9 -1
- package/dist/browser/stores/sync-store/delta-event-window.d.ts +10 -0
- package/dist/browser/stores/sync-store/delta-event-window.d.ts.map +1 -0
- package/dist/browser/stores/sync-store/delta-event-window.js +10 -0
- package/dist/browser/stores/sync-store/delta-event-window.js.map +1 -0
- package/dist/browser/stores/sync-store.d.ts.map +1 -1
- package/dist/browser/stores/sync-store.js +48 -5
- package/dist/browser/stores/sync-store.js.map +1 -1
- package/dist/core/client/kortix.d.ts +5 -0
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +3 -0
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/http/api-client.d.ts.map +1 -1
- package/dist/core/http/api-client.js +26 -1
- package/dist/core/http/api-client.js.map +1 -1
- package/dist/core/rest/platform-client/host-boundary.d.ts +25 -7
- package/dist/core/rest/platform-client/host-boundary.d.ts.map +1 -1
- package/dist/core/rest/platform-client/host-boundary.js.map +1 -1
- package/dist/core/rest/projects-client/accounts.d.ts +5 -0
- package/dist/core/rest/projects-client/accounts.d.ts.map +1 -1
- package/dist/core/rest/projects-client/accounts.js.map +1 -1
- package/dist/core/rest/projects-client/agent-config.d.ts +8 -0
- package/dist/core/rest/projects-client/agent-config.d.ts.map +1 -1
- package/dist/core/rest/projects-client/agent-config.js.map +1 -1
- package/dist/core/rest/projects-client/apps.d.ts +14 -0
- package/dist/core/rest/projects-client/apps.d.ts.map +1 -1
- package/dist/core/rest/projects-client/apps.js +4 -0
- package/dist/core/rest/projects-client/apps.js.map +1 -1
- package/dist/core/rest/projects-client/audit.d.ts +9 -3
- package/dist/core/rest/projects-client/audit.d.ts.map +1 -1
- package/dist/core/rest/projects-client/audit.js.map +1 -1
- package/dist/core/rest/projects-client/connectors.d.ts +31 -0
- package/dist/core/rest/projects-client/connectors.d.ts.map +1 -1
- package/dist/core/rest/projects-client/connectors.js +15 -0
- package/dist/core/rest/projects-client/connectors.js.map +1 -1
- package/dist/core/rest/projects-client/gateway.d.ts +4 -8
- package/dist/core/rest/projects-client/gateway.d.ts.map +1 -1
- package/dist/core/rest/projects-client/gateway.js.map +1 -1
- package/dist/core/rest/projects-client/iam.d.ts +2 -2
- package/dist/core/rest/projects-client/iam.d.ts.map +1 -1
- package/dist/core/rest/projects-client/index.d.ts +1 -0
- package/dist/core/rest/projects-client/index.d.ts.map +1 -1
- package/dist/core/rest/projects-client/index.js +1 -0
- package/dist/core/rest/projects-client/index.js.map +1 -1
- package/dist/core/rest/projects-client/projects.d.ts +15 -1
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js +1 -0
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/rest/projects-client/review-items.d.ts +173 -0
- package/dist/core/rest/projects-client/review-items.d.ts.map +1 -0
- package/dist/core/rest/projects-client/review-items.js +260 -0
- package/dist/core/rest/projects-client/review-items.js.map +1 -0
- package/dist/core/rest/projects-client/session-attachments.d.ts +37 -0
- package/dist/core/rest/projects-client/session-attachments.d.ts.map +1 -1
- package/dist/core/rest/projects-client/session-attachments.js +134 -0
- package/dist/core/rest/projects-client/session-attachments.js.map +1 -1
- package/dist/core/rest/projects-client/session-costs.d.ts +7 -9
- package/dist/core/rest/projects-client/session-costs.d.ts.map +1 -1
- package/dist/core/rest/projects-client/session-costs.js.map +1 -1
- package/dist/core/runtime/attachment-part.d.ts +1 -1
- package/dist/core/runtime/attachment-part.js +1 -1
- package/dist/core/session/connection.d.ts +1 -1
- package/dist/core/session/project-session-read.d.ts +24 -0
- package/dist/core/session/project-session-read.d.ts.map +1 -0
- package/dist/core/session/project-session-read.js +29 -0
- package/dist/core/session/project-session-read.js.map +1 -0
- package/dist/core/session/single-flight.d.ts +20 -0
- package/dist/core/session/single-flight.d.ts.map +1 -0
- package/dist/core/session/single-flight.js +39 -0
- package/dist/core/session/single-flight.js.map +1 -0
- package/dist/core/session/wake-escalation.d.ts +2 -2
- package/dist/core/session/wake-escalation.js +2 -2
- package/dist/core/session/wire-message-id.d.ts +73 -0
- package/dist/core/session/wire-message-id.d.ts.map +1 -0
- package/dist/core/session/wire-message-id.js +120 -0
- package/dist/core/session/wire-message-id.js.map +1 -0
- package/dist/core/session/working.d.ts +2 -2
- package/dist/core/session-sync/session-sync-controller.d.ts +1 -1
- package/dist/core/session-sync/session-sync-controller.js +2 -2
- package/dist/core/turns/grouping.d.ts.map +1 -1
- package/dist/core/turns/grouping.js +46 -2
- package/dist/core/turns/grouping.js.map +1 -1
- package/dist/core/turns/index.d.ts +3 -0
- package/dist/core/turns/index.d.ts.map +1 -1
- package/dist/core/turns/index.js +2 -0
- package/dist/core/turns/index.js.map +1 -1
- package/dist/core/turns/segments/burst-summary.d.ts +49 -0
- package/dist/core/turns/segments/burst-summary.d.ts.map +1 -0
- package/dist/core/turns/segments/burst-summary.js +64 -0
- package/dist/core/turns/segments/burst-summary.js.map +1 -0
- package/dist/core/turns/segments/compaction-state.d.ts +44 -0
- package/dist/core/turns/segments/compaction-state.d.ts.map +1 -0
- package/dist/core/turns/segments/compaction-state.js +79 -0
- package/dist/core/turns/segments/compaction-state.js.map +1 -0
- package/dist/core/turns/segments/group-steps.d.ts +22 -0
- package/dist/core/turns/segments/group-steps.d.ts.map +1 -0
- package/dist/core/turns/segments/group-steps.js +89 -0
- package/dist/core/turns/segments/group-steps.js.map +1 -0
- package/dist/core/turns/segments/index.d.ts +21 -0
- package/dist/core/turns/segments/index.d.ts.map +1 -0
- package/dist/core/turns/segments/index.js +21 -0
- package/dist/core/turns/segments/index.js.map +1 -0
- package/dist/core/turns/segments/merge-steps.d.ts +79 -0
- package/dist/core/turns/segments/merge-steps.d.ts.map +1 -0
- package/dist/core/turns/segments/merge-steps.js +190 -0
- package/dist/core/turns/segments/merge-steps.js.map +1 -0
- package/dist/core/turns/segments/message-time.d.ts +86 -0
- package/dist/core/turns/segments/message-time.d.ts.map +1 -0
- package/dist/core/turns/segments/message-time.js +196 -0
- package/dist/core/turns/segments/message-time.js.map +1 -0
- package/dist/core/turns/segments/narration.d.ts +71 -0
- package/dist/core/turns/segments/narration.d.ts.map +1 -0
- package/dist/core/turns/segments/narration.js +836 -0
- package/dist/core/turns/segments/narration.js.map +1 -0
- package/dist/core/turns/segments/segment-turn.d.ts +26 -0
- package/dist/core/turns/segments/segment-turn.d.ts.map +1 -0
- package/dist/core/turns/segments/segment-turn.js +36 -0
- package/dist/core/turns/segments/segment-turn.js.map +1 -0
- package/dist/core/turns/segments/session-activity-groups.d.ts +93 -0
- package/dist/core/turns/segments/session-activity-groups.d.ts.map +1 -0
- package/dist/core/turns/segments/session-activity-groups.js +127 -0
- package/dist/core/turns/segments/session-activity-groups.js.map +1 -0
- package/dist/core/turns/segments/step-label.d.ts +44 -0
- package/dist/core/turns/segments/step-label.d.ts.map +1 -0
- package/dist/core/turns/segments/step-label.js +129 -0
- package/dist/core/turns/segments/step-label.js.map +1 -0
- package/dist/core/turns/segments/turn-busy-visibility.d.ts +51 -0
- package/dist/core/turns/segments/turn-busy-visibility.d.ts.map +1 -0
- package/dist/core/turns/segments/turn-busy-visibility.js +47 -0
- package/dist/core/turns/segments/turn-busy-visibility.js.map +1 -0
- package/dist/core/turns/segments/working-turn.d.ts +165 -0
- package/dist/core/turns/segments/working-turn.d.ts.map +1 -0
- package/dist/core/turns/segments/working-turn.js +168 -0
- package/dist/core/turns/segments/working-turn.js.map +1 -0
- package/dist/core/turns/text-scan.d.ts +65 -0
- package/dist/core/turns/text-scan.d.ts.map +1 -0
- package/dist/core/turns/text-scan.js +344 -0
- package/dist/core/turns/text-scan.js.map +1 -0
- package/dist/core/turns/tools/agent-helpers.d.ts +10 -0
- package/dist/core/turns/tools/agent-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/agent-helpers.js +54 -0
- package/dist/core/turns/tools/agent-helpers.js.map +1 -0
- package/dist/core/turns/tools/file-verb.d.ts +81 -0
- package/dist/core/turns/tools/file-verb.d.ts.map +1 -0
- package/dist/core/turns/tools/file-verb.js +70 -0
- package/dist/core/turns/tools/file-verb.js.map +1 -0
- package/dist/core/turns/tools/index.d.ts +22 -0
- package/dist/core/turns/tools/index.d.ts.map +1 -0
- package/dist/core/turns/tools/index.js +22 -0
- package/dist/core/turns/tools/index.js.map +1 -0
- package/dist/core/turns/tools/memory-helpers.d.ts +16 -0
- package/dist/core/turns/tools/memory-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/memory-helpers.js +55 -0
- package/dist/core/turns/tools/memory-helpers.js.map +1 -0
- package/dist/core/turns/tools/patch-summary.d.ts +53 -0
- package/dist/core/turns/tools/patch-summary.d.ts.map +1 -0
- package/dist/core/turns/tools/patch-summary.js +71 -0
- package/dist/core/turns/tools/patch-summary.js.map +1 -0
- package/dist/core/turns/tools/presentation-helpers.d.ts +16 -0
- package/dist/core/turns/tools/presentation-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/presentation-helpers.js +18 -0
- package/dist/core/turns/tools/presentation-helpers.js.map +1 -0
- package/dist/core/turns/tools/question-helpers.d.ts +10 -0
- package/dist/core/turns/tools/question-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/question-helpers.js +13 -0
- package/dist/core/turns/tools/question-helpers.js.map +1 -0
- package/dist/core/turns/tools/read-helpers.d.ts +8 -0
- package/dist/core/turns/tools/read-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/read-helpers.js +25 -0
- package/dist/core/turns/tools/read-helpers.js.map +1 -0
- package/dist/core/turns/tools/search-query.d.ts +28 -0
- package/dist/core/turns/tools/search-query.d.ts.map +1 -0
- package/dist/core/turns/tools/search-query.js +137 -0
- package/dist/core/turns/tools/search-query.js.map +1 -0
- package/dist/core/turns/tools/show-availability.d.ts +53 -0
- package/dist/core/turns/tools/show-availability.d.ts.map +1 -0
- package/dist/core/turns/tools/show-availability.js +110 -0
- package/dist/core/turns/tools/show-availability.js.map +1 -0
- package/dist/core/turns/tools/skill-helpers.d.ts +35 -0
- package/dist/core/turns/tools/skill-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/skill-helpers.js +129 -0
- package/dist/core/turns/tools/skill-helpers.js.map +1 -0
- package/dist/core/turns/tools/tool-meta.d.ts +72 -0
- package/dist/core/turns/tools/tool-meta.d.ts.map +1 -0
- package/dist/core/turns/tools/tool-meta.js +174 -0
- package/dist/core/turns/tools/tool-meta.js.map +1 -0
- package/dist/core/turns/tools/tool-outcome.d.ts +78 -0
- package/dist/core/turns/tools/tool-outcome.d.ts.map +1 -0
- package/dist/core/turns/tools/tool-outcome.js +244 -0
- package/dist/core/turns/tools/tool-outcome.js.map +1 -0
- package/dist/core/turns/tools/tool-output-format.d.ts +63 -0
- package/dist/core/turns/tools/tool-output-format.d.ts.map +1 -0
- package/dist/core/turns/tools/tool-output-format.js +174 -0
- package/dist/core/turns/tools/tool-output-format.js.map +1 -0
- package/dist/core/turns/tools/web-helpers.d.ts +40 -0
- package/dist/core/turns/tools/web-helpers.d.ts.map +1 -0
- package/dist/core/turns/tools/web-helpers.js +297 -0
- package/dist/core/turns/tools/web-helpers.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/kortix.esm.min.js +42 -26
- package/dist/kortix.global.js +42 -26
- package/dist/node/app-viewer.js +1 -1
- package/dist/platform/auth-core.d.ts +1 -1
- package/dist/platform/auth-core.js +1 -1
- package/dist/react/bedrock-invokable.d.ts +2 -2
- package/dist/react/bedrock-invokable.js +2 -2
- package/dist/react/opencode.d.ts +2 -0
- package/dist/react/opencode.d.ts.map +1 -1
- package/dist/react/opencode.js +2 -0
- package/dist/react/opencode.js.map +1 -1
- package/dist/react/prefetch-session-open.d.ts +20 -0
- package/dist/react/prefetch-session-open.d.ts.map +1 -0
- package/dist/react/prefetch-session-open.js +54 -0
- package/dist/react/prefetch-session-open.js.map +1 -0
- package/dist/react/provider-refresh.d.ts.map +1 -1
- package/dist/react/provider-refresh.js +24 -14
- package/dist/react/provider-refresh.js.map +1 -1
- package/dist/react/provider-selection.d.ts +4 -0
- package/dist/react/provider-selection.d.ts.map +1 -1
- package/dist/react/provider-selection.js +6 -2
- package/dist/react/provider-selection.js.map +1 -1
- package/dist/react/session-transcript-subscription.d.ts +29 -0
- package/dist/react/session-transcript-subscription.d.ts.map +1 -0
- package/dist/react/session-transcript-subscription.js +94 -0
- package/dist/react/session-transcript-subscription.js.map +1 -0
- package/dist/react/sign-in-with-kortix.d.ts +3 -3
- package/dist/react/use-model-store.d.ts +1 -1
- package/dist/react/use-model-store.js +1 -1
- package/dist/react/use-opencode-sessions/messages.d.ts +14 -3
- package/dist/react/use-opencode-sessions/messages.d.ts.map +1 -1
- package/dist/react/use-opencode-sessions/messages.js +92 -115
- package/dist/react/use-opencode-sessions/messages.js.map +1 -1
- package/dist/react/use-project-session.d.ts.map +1 -1
- package/dist/react/use-project-session.js +10 -2
- package/dist/react/use-project-session.js.map +1 -1
- package/dist/react/use-session-messages.d.ts +37 -0
- package/dist/react/use-session-messages.d.ts.map +1 -0
- package/dist/react/use-session-messages.js +83 -0
- package/dist/react/use-session-messages.js.map +1 -0
- package/dist/react/use-session-prompts.d.ts.map +1 -1
- package/dist/react/use-session-prompts.js +11 -2
- package/dist/react/use-session-prompts.js.map +1 -1
- package/dist/react/use-session-sync.d.ts +9 -0
- package/dist/react/use-session-sync.d.ts.map +1 -1
- package/dist/react/use-session-sync.js +6 -2
- package/dist/react/use-session-sync.js.map +1 -1
- package/dist/react/use-session-working.d.ts.map +1 -1
- package/dist/react/use-session-working.js +20 -10
- package/dist/react/use-session-working.js.map +1 -1
- package/dist/react/use-session.d.ts +18 -0
- package/dist/react/use-session.d.ts.map +1 -1
- package/dist/react/use-session.js +9 -1
- package/dist/react/use-session.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-outcome + JSON-failure parsing — pure helpers, no React.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `infrastructure.tsx` so the verdict logic (the predicates
|
|
5
|
+
* every tool renderer shares) and the `{success:false,error}` failure
|
|
6
|
+
* contract parser are testable WITHOUT loading the 1500-line React module
|
|
7
|
+
* that renders them. `infrastructure.tsx` re-exports everything here so
|
|
8
|
+
* existing call sites keep their imports unchanged.
|
|
9
|
+
*
|
|
10
|
+
* No React / DOM / framework imports allowed — type-only imports only.
|
|
11
|
+
*/
|
|
12
|
+
import { jsonTail, stripErrorPrefixes } from '../text-scan.js';
|
|
13
|
+
/** A JSON value that owns properties — i.e. a plain object, not null/array. */
|
|
14
|
+
function isJsonObject(value) {
|
|
15
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
export function looksLikeError(text) {
|
|
18
|
+
const t = text.trim();
|
|
19
|
+
if (t.length > 500)
|
|
20
|
+
return false;
|
|
21
|
+
if (/^Error:\s/i.test(t))
|
|
22
|
+
return true;
|
|
23
|
+
if (/^([\w._-]+Error|[\w._-]+Exception):\s/i.test(t))
|
|
24
|
+
return true;
|
|
25
|
+
if (/Traceback \(most recent call last\)/i.test(t))
|
|
26
|
+
return true;
|
|
27
|
+
if (/^\s*\[\s*\{[\s\S]*"message"\s*:/.test(t))
|
|
28
|
+
return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* True when a completed tool's output is an error rather than a result —
|
|
33
|
+
* either a plain error/traceback string or the `{success:false,error}` contract.
|
|
34
|
+
* Tools whose own parser returns nothing should fall back to rendering the
|
|
35
|
+
* error (via `ToolOutputFallback`) instead of a blank panel.
|
|
36
|
+
*/
|
|
37
|
+
export function isErrorOutput(output) {
|
|
38
|
+
return !!output && (looksLikeError(output) || parseJsonFailure(output) !== null);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether a settled tool call succeeded, half-succeeded, or failed.
|
|
42
|
+
*
|
|
43
|
+
* Three different shapes mean "this failed", and only the first of them used to
|
|
44
|
+
* reach the row's icon:
|
|
45
|
+
* - the call threw — `state.status === 'error'`
|
|
46
|
+
* - the call RETURNED the error — completed, output is `Error: …` or the
|
|
47
|
+
* `{success:false,error}` contract
|
|
48
|
+
* - the call returned a batch — completed, `results[]` with some or all
|
|
49
|
+
* items `success:false` (scrape_webpage over three URLs, one dead host)
|
|
50
|
+
*
|
|
51
|
+
* Every tool renderer hardcodes its own leading icon — `GlobeIcon` for scrape,
|
|
52
|
+
* a favicon for web_fetch, a terminal for bash — and none of them read the
|
|
53
|
+
* output, so shapes two and three kept drawing "web page" over a failure. This
|
|
54
|
+
* is the one predicate they all share; see {@link ToolOutcomeContext}.
|
|
55
|
+
*
|
|
56
|
+
* A running call is `ok`: it has no verdict yet. The shimmer already says
|
|
57
|
+
* "in flight", and painting a warning on unfinished work is a worse lie than
|
|
58
|
+
* the one this fixes.
|
|
59
|
+
*/
|
|
60
|
+
export function partOutcome(part) {
|
|
61
|
+
const cached = OUTCOME_CACHE.get(part);
|
|
62
|
+
// Guarded on `state`, not just on the part: the cache is only sound while the
|
|
63
|
+
// thing it was computed from is the same object.
|
|
64
|
+
if (cached && cached.state === part.state)
|
|
65
|
+
return cached.outcome;
|
|
66
|
+
const outcome = computeOutcome(part);
|
|
67
|
+
OUTCOME_CACHE.set(part, { state: part.state, outcome });
|
|
68
|
+
return outcome;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The verdict, memoised per part.
|
|
72
|
+
*
|
|
73
|
+
* `partOutcome` is called from four places and none of them are rare: once per
|
|
74
|
+
* tool row in `ToolPartRenderer`, once per part in `burstSummary`, once per part
|
|
75
|
+
* in a file-chip run, and once per bare `ActivityStep`. So a burst of ten tool
|
|
76
|
+
* calls asks this question twelve times — and asks it again on every SSE frame,
|
|
77
|
+
* because the memos above it are invalidated by the turn's identity changing.
|
|
78
|
+
*
|
|
79
|
+
* Uncached, each of those calls did a full `.trim()` copy plus up to TWO
|
|
80
|
+
* complete `JSON.parse` runs (see `computeOutcome`) over an output that can be
|
|
81
|
+
* hundreds of kilobytes for a `scrape_webpage` or a `web_search`.
|
|
82
|
+
*
|
|
83
|
+
* A `WeakMap` is exactly the right shape here: a part is immutable and is
|
|
84
|
+
* REPLACED rather than mutated when it changes (`sync-store` swaps the element),
|
|
85
|
+
* so the key is a natural version stamp, and entries die with the parts.
|
|
86
|
+
*/
|
|
87
|
+
const OUTCOME_CACHE = new WeakMap();
|
|
88
|
+
function computeOutcome(part) {
|
|
89
|
+
const state = part.state;
|
|
90
|
+
if (state.status === 'error')
|
|
91
|
+
return 'failed';
|
|
92
|
+
if (state.status !== 'completed')
|
|
93
|
+
return 'ok';
|
|
94
|
+
const output = typeof state.output === 'string' ? state.output.trim() : '';
|
|
95
|
+
if (!output)
|
|
96
|
+
return 'ok';
|
|
97
|
+
if (looksLikeError(output))
|
|
98
|
+
return 'failed';
|
|
99
|
+
// ONE parse answers both remaining questions. `isErrorOutput` → `parseJsonFailure`
|
|
100
|
+
// parsed the whole output to ask "is this the {success:false} contract?", and
|
|
101
|
+
// then `batchOutcome` parsed the identical string again to ask "does it hold a
|
|
102
|
+
// results[] array?". Two passes over the same bytes, every call.
|
|
103
|
+
const parsed = tryParseJson(output);
|
|
104
|
+
if (parsed === undefined)
|
|
105
|
+
return 'ok';
|
|
106
|
+
if (isJsonFailure(parsed))
|
|
107
|
+
return 'failed';
|
|
108
|
+
return batchOutcomeOf(parsed);
|
|
109
|
+
}
|
|
110
|
+
/** `undefined` when the text is not JSON — distinct from a parsed `undefined`. */
|
|
111
|
+
function tryParseJson(text) {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.parse(text);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** The boolean half of {@link parseJsonFailure}, without rebuilding its result. */
|
|
120
|
+
function isJsonFailure(parsed) {
|
|
121
|
+
return isJsonObject(parsed) && parsed.success === false && typeof parsed.error === 'string';
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A batch tool's per-item verdicts collapsed into one outcome.
|
|
125
|
+
*
|
|
126
|
+
* `scrape_webpage` returns `{total, successful, failed, results:[{success}]}`.
|
|
127
|
+
* Two good pages and one dead host is a real and common result that is neither
|
|
128
|
+
* "ok" nor "failed" — it earns amber, not red. Counted from `results[]` rather
|
|
129
|
+
* than the sibling `failed` field because that field is optional, while the
|
|
130
|
+
* array is the thing actually rendered in the card.
|
|
131
|
+
*/
|
|
132
|
+
function batchOutcomeOf(parsed) {
|
|
133
|
+
const results = isJsonObject(parsed) ? parsed.results : undefined;
|
|
134
|
+
if (!Array.isArray(results) || results.length === 0)
|
|
135
|
+
return 'ok';
|
|
136
|
+
const failed = results.filter((item) => item !== null &&
|
|
137
|
+
typeof item === 'object' &&
|
|
138
|
+
item.success === false).length;
|
|
139
|
+
if (failed === 0)
|
|
140
|
+
return 'ok';
|
|
141
|
+
return failed === results.length ? 'failed' : 'partial';
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Parse the `{success:false,error,hint?}` failure contract out of a tool's
|
|
145
|
+
* output. Returns null when the output isn't that contract.
|
|
146
|
+
*
|
|
147
|
+
* The parsed JSON must be a plain OBJECT before any field is read. A tool that
|
|
148
|
+
* returns the literal `null` (or any JSON value that parses to a non-object —
|
|
149
|
+
* `true`, `5`, `"x"`, …) used to reach `parsed.success` on `null` and throw
|
|
150
|
+
* `Cannot read properties of null (reading 'success')`, which crashed the
|
|
151
|
+
* session page's turn render via `partOutcome` → `isErrorOutput` → here
|
|
152
|
+
* (Better Stack patterns `487ae241…` / `ce68779d…`, prod v0.12.4). Any value
|
|
153
|
+
* that isn't an object is, by definition, not the failure contract → null.
|
|
154
|
+
*/
|
|
155
|
+
export function parseJsonFailure(output) {
|
|
156
|
+
const trimmed = output.trim();
|
|
157
|
+
if (!trimmed)
|
|
158
|
+
return null;
|
|
159
|
+
let parsed;
|
|
160
|
+
try {
|
|
161
|
+
parsed = JSON.parse(trimmed);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (!isJsonObject(parsed))
|
|
167
|
+
return null;
|
|
168
|
+
if (parsed.success !== false || typeof parsed.error !== 'string')
|
|
169
|
+
return null;
|
|
170
|
+
const result = {
|
|
171
|
+
errorSummary: parsed.error.trim(),
|
|
172
|
+
hint: typeof parsed.hint === 'string' ? parsed.hint.trim() : undefined,
|
|
173
|
+
};
|
|
174
|
+
const nestedJson = jsonTail(result.errorSummary);
|
|
175
|
+
if (nestedJson === null)
|
|
176
|
+
return result;
|
|
177
|
+
try {
|
|
178
|
+
const nested = JSON.parse(nestedJson);
|
|
179
|
+
if (typeof nested.message === 'string' && nested.message.trim()) {
|
|
180
|
+
result.nestedMessage = nested.message.trim();
|
|
181
|
+
}
|
|
182
|
+
if (typeof nested.status === 'number') {
|
|
183
|
+
result.status = nested.status;
|
|
184
|
+
}
|
|
185
|
+
if (typeof nested.error === 'boolean') {
|
|
186
|
+
result.nestedError = nested.error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch { }
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Normalize a backend error string for display: strip the noisy, often
|
|
194
|
+
* duplicated `Error:` prefixes (e.g. "Error: … Error: Error: …") and collapse
|
|
195
|
+
* whitespace, so the panel shows one calm sentence instead of stack-y jargon.
|
|
196
|
+
* Falls back to the trimmed original if cleaning would empty the string.
|
|
197
|
+
*/
|
|
198
|
+
export function cleanErrorMessage(raw) {
|
|
199
|
+
const cleaned = stripErrorPrefixes(raw).replace(/\s+/g, ' ').trim();
|
|
200
|
+
return cleaned || raw.trim();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Format the `{success:false,error,hint?}` failure contract as a plain text
|
|
204
|
+
* block (error + nested message + hint). Returns null when the output isn't
|
|
205
|
+
* that contract. Same null-object guard as {@link parseJsonFailure} — a tool
|
|
206
|
+
* that returns the literal `null` is not the failure contract.
|
|
207
|
+
*/
|
|
208
|
+
export function formatJsonFailureOutput(output) {
|
|
209
|
+
const trimmed = output.trim();
|
|
210
|
+
if (!trimmed)
|
|
211
|
+
return null;
|
|
212
|
+
let parsed;
|
|
213
|
+
try {
|
|
214
|
+
parsed = JSON.parse(trimmed);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
if (!isJsonObject(parsed))
|
|
220
|
+
return null;
|
|
221
|
+
const success = parsed.success;
|
|
222
|
+
const error = parsed.error;
|
|
223
|
+
const hint = parsed.hint;
|
|
224
|
+
if (success !== false || typeof error !== 'string')
|
|
225
|
+
return null;
|
|
226
|
+
const lines = [];
|
|
227
|
+
lines.push(error.trim());
|
|
228
|
+
const nestedJson = jsonTail(error);
|
|
229
|
+
if (nestedJson !== null) {
|
|
230
|
+
try {
|
|
231
|
+
const nested = JSON.parse(nestedJson);
|
|
232
|
+
const nestedMessage = nested.message;
|
|
233
|
+
if (typeof nestedMessage === 'string' && nestedMessage.trim()) {
|
|
234
|
+
lines.push(`Details: ${nestedMessage.trim()}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch { }
|
|
238
|
+
}
|
|
239
|
+
if (typeof hint === 'string' && hint.trim()) {
|
|
240
|
+
lines.push(`Hint: ${hint.trim()}`);
|
|
241
|
+
}
|
|
242
|
+
return lines.join('\n\n');
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=tool-outcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-outcome.js","sourceRoot":"","sources":["../../../../src/core/turns/tools/tool-outcome.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAa5D,+EA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E,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared formatting for raw tool input/output blobs so oversized, truncated, or
|
|
3
|
+
* JSON-heavy payloads render as tidy, capped content instead of a garbled wall
|
|
4
|
+
* of text. Used by the default tool-output fallback and the web_search / scrape
|
|
5
|
+
* renderers.
|
|
6
|
+
*/
|
|
7
|
+
/** Does this payload look like a JSON object/array (incl. truncated)? */
|
|
8
|
+
export declare function looksLikeJsonPayload(text: string | undefined): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Pretty-print a raw output blob when it parses as JSON (including the
|
|
11
|
+
* double-encoded string case), then cap it to `maxChars`. Non-JSON text is
|
|
12
|
+
* left as-is and capped. Returns the trimmed text plus how many characters
|
|
13
|
+
* were dropped so the UI can show a "+N more" hint.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatRawOutput(output: string | undefined, maxChars?: number): {
|
|
16
|
+
text: string;
|
|
17
|
+
truncatedChars: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Turn a scraped/searched page's raw content into a clean one-line preview:
|
|
21
|
+
* drop markdown image/link syntax and heading/emphasis marks, collapse
|
|
22
|
+
* whitespace and immediately-repeated words (a common artifact of hover-reveal
|
|
23
|
+
* site text), then cap to `maxChars`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function cleanResultSnippet(content: string | undefined, maxChars?: number): string;
|
|
26
|
+
export interface EmbeddedFailure {
|
|
27
|
+
/** Fully-unwrapped, human-readable error message. */
|
|
28
|
+
message: string;
|
|
29
|
+
/** HTTP status code recovered from a nested error payload, if any. */
|
|
30
|
+
status?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Detect the "well-known" embedded-failure shape some tools return even when
|
|
34
|
+
* the outer part state is `completed`: a JSON object with `success: false`
|
|
35
|
+
* and a string `error` field — e.g. a `web_search` call that hit a 402 from
|
|
36
|
+
* the search provider still reports `state.status: "completed"` because the
|
|
37
|
+
* *tool call* completed, only the underlying request failed.
|
|
38
|
+
*
|
|
39
|
+
* The `error` string is frequently itself a wrapper around a nested JSON
|
|
40
|
+
* error object (proxy error → upstream error), e.g.
|
|
41
|
+
* `"Error: 402 Error: {\"message\":\"Insufficient credits\",\"status\":402}"`.
|
|
42
|
+
* This unwraps up to a few levels of that nesting so callers can show the
|
|
43
|
+
* innermost human message ("Insufficient credits") instead of the raw blob.
|
|
44
|
+
*
|
|
45
|
+
* Deliberately conservative: only matches this exact `{success:false,
|
|
46
|
+
* error:string}` shape so it never misfires on legitimate tool payloads that
|
|
47
|
+
* happen to contain the words "success" or "error".
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseEmbeddedFailure(output: string | undefined): EmbeddedFailure | null;
|
|
50
|
+
export interface RecoveredResult {
|
|
51
|
+
title: string;
|
|
52
|
+
url: string;
|
|
53
|
+
snippet?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Best-effort extraction of {title, url, snippet} records from a raw — and
|
|
57
|
+
* possibly truncated or oversized — web-search/scrape JSON blob. Used when
|
|
58
|
+
* strict JSON.parse fails (the model's tool output is frequently truncated mid
|
|
59
|
+
* stream) so the UI can still show clean result cards instead of dumping the
|
|
60
|
+
* raw JSON. Scans field by field, so a cut-off tail just drops its last record.
|
|
61
|
+
*/
|
|
62
|
+
export declare function recoverLinkResults(raw: string | undefined, max?: number): RecoveredResult[];
|
|
63
|
+
//# sourceMappingURL=tool-output-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-output-format.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/tools/tool-output-format.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGtE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,SAAO,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAuB1C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,SAAM,GAAG,MAAM,CAStF;AAED,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CA+CvF;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAUD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,SAAK,GAAG,eAAe,EAAE,CAkCvF"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { jsonTail } from '../text-scan.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shared formatting for raw tool input/output blobs so oversized, truncated, or
|
|
4
|
+
* JSON-heavy payloads render as tidy, capped content instead of a garbled wall
|
|
5
|
+
* of text. Used by the default tool-output fallback and the web_search / scrape
|
|
6
|
+
* renderers.
|
|
7
|
+
*/
|
|
8
|
+
/** Does this payload look like a JSON object/array (incl. truncated)? */
|
|
9
|
+
export function looksLikeJsonPayload(text) {
|
|
10
|
+
const s = (text ?? '').trimStart();
|
|
11
|
+
return s.startsWith('{') || s.startsWith('[');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Pretty-print a raw output blob when it parses as JSON (including the
|
|
15
|
+
* double-encoded string case), then cap it to `maxChars`. Non-JSON text is
|
|
16
|
+
* left as-is and capped. Returns the trimmed text plus how many characters
|
|
17
|
+
* were dropped so the UI can show a "+N more" hint.
|
|
18
|
+
*/
|
|
19
|
+
export function formatRawOutput(output, maxChars = 2000) {
|
|
20
|
+
let s = (output ?? '').trim();
|
|
21
|
+
try {
|
|
22
|
+
let value = JSON.parse(s);
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
try {
|
|
25
|
+
value = JSON.parse(value);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
/* keep the inner string */
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (value && typeof value === 'object') {
|
|
32
|
+
s = JSON.stringify(value, null, 2);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* not JSON — leave as raw text */
|
|
37
|
+
}
|
|
38
|
+
if (s.length > maxChars) {
|
|
39
|
+
return { text: s.slice(0, maxChars).trimEnd(), truncatedChars: s.length - maxChars };
|
|
40
|
+
}
|
|
41
|
+
return { text: s, truncatedChars: 0 };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Turn a scraped/searched page's raw content into a clean one-line preview:
|
|
45
|
+
* drop markdown image/link syntax and heading/emphasis marks, collapse
|
|
46
|
+
* whitespace and immediately-repeated words (a common artifact of hover-reveal
|
|
47
|
+
* site text), then cap to `maxChars`.
|
|
48
|
+
*/
|
|
49
|
+
export function cleanResultSnippet(content, maxChars = 200) {
|
|
50
|
+
let s = content ?? '';
|
|
51
|
+
s = s.replace(/\\n/g, ' '); // literal escaped newlines
|
|
52
|
+
s = s.replace(/!\[[^\]]*\]\([^)]*\)/g, ' '); // markdown images
|
|
53
|
+
s = s.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1'); // markdown links → text
|
|
54
|
+
s = s.replace(/[#*_`>]+/g, ' '); // heading / emphasis / code / quote marks
|
|
55
|
+
s = s.replace(/\s+/g, ' ').trim(); // collapse whitespace
|
|
56
|
+
s = s.replace(/\b(\w{2,})(?:\s+\1\b)+/gi, '$1'); // collapse repeated words
|
|
57
|
+
return s.length > maxChars ? s.slice(0, maxChars).trimEnd() + '…' : s;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Detect the "well-known" embedded-failure shape some tools return even when
|
|
61
|
+
* the outer part state is `completed`: a JSON object with `success: false`
|
|
62
|
+
* and a string `error` field — e.g. a `web_search` call that hit a 402 from
|
|
63
|
+
* the search provider still reports `state.status: "completed"` because the
|
|
64
|
+
* *tool call* completed, only the underlying request failed.
|
|
65
|
+
*
|
|
66
|
+
* The `error` string is frequently itself a wrapper around a nested JSON
|
|
67
|
+
* error object (proxy error → upstream error), e.g.
|
|
68
|
+
* `"Error: 402 Error: {\"message\":\"Insufficient credits\",\"status\":402}"`.
|
|
69
|
+
* This unwraps up to a few levels of that nesting so callers can show the
|
|
70
|
+
* innermost human message ("Insufficient credits") instead of the raw blob.
|
|
71
|
+
*
|
|
72
|
+
* Deliberately conservative: only matches this exact `{success:false,
|
|
73
|
+
* error:string}` shape so it never misfires on legitimate tool payloads that
|
|
74
|
+
* happen to contain the words "success" or "error".
|
|
75
|
+
*/
|
|
76
|
+
export function parseEmbeddedFailure(output) {
|
|
77
|
+
const trimmed = (output ?? '').trim();
|
|
78
|
+
if (!trimmed)
|
|
79
|
+
return null;
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = JSON.parse(trimmed);
|
|
83
|
+
if (typeof parsed === 'string') {
|
|
84
|
+
try {
|
|
85
|
+
parsed = JSON.parse(parsed);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
96
|
+
return null;
|
|
97
|
+
const obj = parsed;
|
|
98
|
+
if (obj.success !== false || typeof obj.error !== 'string' || !obj.error.trim())
|
|
99
|
+
return null;
|
|
100
|
+
let message = obj.error.trim();
|
|
101
|
+
let status;
|
|
102
|
+
// Unwrap `... : {json}` tails: proxy errors often wrap an upstream error
|
|
103
|
+
// object. Walk a few levels deep so a doubly-wrapped message still resolves.
|
|
104
|
+
for (let i = 0; i < 3; i++) {
|
|
105
|
+
const nestedJson = jsonTail(message);
|
|
106
|
+
if (nestedJson === null)
|
|
107
|
+
break;
|
|
108
|
+
let nested;
|
|
109
|
+
try {
|
|
110
|
+
nested = JSON.parse(nestedJson);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (typeof nested.status === 'number')
|
|
116
|
+
status = nested.status;
|
|
117
|
+
if (typeof nested.message === 'string' && nested.message.trim()) {
|
|
118
|
+
message = nested.message.trim();
|
|
119
|
+
}
|
|
120
|
+
else if (typeof nested.error === 'string' && nested.error.trim()) {
|
|
121
|
+
message = nested.error.trim();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { message, status };
|
|
128
|
+
}
|
|
129
|
+
function decodeJsonStringLiteral(escaped) {
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(`"${escaped}"`);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return escaped;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Best-effort extraction of {title, url, snippet} records from a raw — and
|
|
139
|
+
* possibly truncated or oversized — web-search/scrape JSON blob. Used when
|
|
140
|
+
* strict JSON.parse fails (the model's tool output is frequently truncated mid
|
|
141
|
+
* stream) so the UI can still show clean result cards instead of dumping the
|
|
142
|
+
* raw JSON. Scans field by field, so a cut-off tail just drops its last record.
|
|
143
|
+
*/
|
|
144
|
+
export function recoverLinkResults(raw, max = 30) {
|
|
145
|
+
if (!raw)
|
|
146
|
+
return [];
|
|
147
|
+
const out = [];
|
|
148
|
+
const seen = new Set();
|
|
149
|
+
const push = (title, url, snippet) => {
|
|
150
|
+
if (!/^https?:\/\//i.test(url) || seen.has(url) || out.length >= max)
|
|
151
|
+
return;
|
|
152
|
+
seen.add(url);
|
|
153
|
+
out.push({ title: title.trim() || url, url, snippet: snippet?.trim() || undefined });
|
|
154
|
+
};
|
|
155
|
+
// title → url (→ snippet/content/text): the common search-result ordering.
|
|
156
|
+
const titleFirst = /"title"\s*:\s*"((?:\\.|[^"\\])*)"\s*,\s*"url"\s*:\s*"((?:\\.|[^"\\])*)"(?:\s*,\s*"(?:snippet|content|text)"\s*:\s*"((?:\\.|[^"\\])*)")?/g;
|
|
157
|
+
let m;
|
|
158
|
+
while ((m = titleFirst.exec(raw)) !== null) {
|
|
159
|
+
push(decodeJsonStringLiteral(m[1]), decodeJsonStringLiteral(m[2]), m[3] ? decodeJsonStringLiteral(m[3]) : undefined);
|
|
160
|
+
if (out.length >= max)
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
// url → … → title (scrape ordering), only if the first pass found nothing.
|
|
164
|
+
if (out.length === 0) {
|
|
165
|
+
const urlFirst = /"url"\s*:\s*"((?:\\.|[^"\\])*)"[^{}]{0,400}?"title"\s*:\s*"((?:\\.|[^"\\])*)"/g;
|
|
166
|
+
while ((m = urlFirst.exec(raw)) !== null) {
|
|
167
|
+
push(decodeJsonStringLiteral(m[2]), decodeJsonStringLiteral(m[1]));
|
|
168
|
+
if (out.length >= max)
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=tool-output-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-output-format.js","sourceRoot":"","sources":["../../../../src/core/turns/tools/tool-output-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAA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IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC3C,IAAI,CACF,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC7B,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC7B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CACjD,CAAC;QACF,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;IACpC,CAAC;IAED,2EAA2E;IAC3E,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,QAAQ,GACZ,gFAAgF,CAAC;QACnF,OAAO,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACzC,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACnE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface WebSearchSource {
|
|
2
|
+
title: string;
|
|
3
|
+
url: string;
|
|
4
|
+
snippet?: string;
|
|
5
|
+
author?: string;
|
|
6
|
+
publishedDate?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WebSearchQueryResult {
|
|
9
|
+
query: string;
|
|
10
|
+
answer?: string;
|
|
11
|
+
sources: WebSearchSource[];
|
|
12
|
+
}
|
|
13
|
+
export declare function parseWebSearchOutput(output: string | any): WebSearchQueryResult[];
|
|
14
|
+
export declare function wsDomain(url: string): string;
|
|
15
|
+
/** Registrable domain for grouping subdomains (e.g. photos.google.com → google.com). */
|
|
16
|
+
export declare function wsRootDomain(url: string): string;
|
|
17
|
+
/** A page URL → its favicon, via Google's favicon service; `null` for a non-URL. */
|
|
18
|
+
export declare function wsFavicon(url: string): string | null;
|
|
19
|
+
export interface ScrapeResult {
|
|
20
|
+
url: string;
|
|
21
|
+
success: boolean;
|
|
22
|
+
title?: string;
|
|
23
|
+
content?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ParsedScrapeOutput {
|
|
27
|
+
total: number;
|
|
28
|
+
successful: number;
|
|
29
|
+
failed: number;
|
|
30
|
+
results: ScrapeResult[];
|
|
31
|
+
}
|
|
32
|
+
export declare function looksLikeHtml(s: string): boolean;
|
|
33
|
+
/** URLs from scrape_webpage input (`urls` string or array). */
|
|
34
|
+
export declare function parseScrapeInputUrls(input: Record<string, unknown>): string[];
|
|
35
|
+
/** Build per-URL failure cards when the tool returns a plain error string. */
|
|
36
|
+
export declare function buildScrapeFailureResults(output: string, urls: string[]): ScrapeResult[];
|
|
37
|
+
/** Parsed scrape results, or per-input-URL failure cards for plain error output. */
|
|
38
|
+
export declare function resolveScrapeResults(output: string | unknown, input: Record<string, unknown>): ScrapeResult[];
|
|
39
|
+
export declare function parseScrapeOutput(output: string | any): ParsedScrapeOutput | null;
|
|
40
|
+
//# sourceMappingURL=web-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-helpers.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/tools/web-helpers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,M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