veryfront 0.1.337 → 0.1.339
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/esm/deno.js +1 -1
- package/esm/src/agent/default-research-artifact-policy.d.ts +28 -0
- package/esm/src/agent/default-research-artifact-policy.d.ts.map +1 -0
- package/esm/src/agent/default-research-artifact-policy.js +99 -0
- package/esm/src/agent/default-research-artifact-support.d.ts +39 -0
- package/esm/src/agent/default-research-artifact-support.d.ts.map +1 -0
- package/esm/src/agent/default-research-artifact-support.js +184 -0
- package/esm/src/agent/index.d.ts +3 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +3 -0
- package/esm/src/agent/slash-command-artifact-policy.d.ts +14 -0
- package/esm/src/agent/slash-command-artifact-policy.d.ts.map +1 -0
- package/esm/src/agent/slash-command-artifact-policy.js +138 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +1 -1
- package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/global.d.ts +0 -1
- package/src/deps/esm.sh/@types/{react@19.2.14 → react@19.2.3}/index.d.ts +24 -93
- package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +1 -1
- package/src/src/agent/default-research-artifact-policy.ts +146 -0
- package/src/src/agent/default-research-artifact-support.ts +289 -0
- package/src/src/agent/index.ts +24 -0
- package/src/src/agent/slash-command-artifact-policy.ts +212 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -16,7 +16,6 @@ type NativeKeyboardEvent = KeyboardEvent;
|
|
|
16
16
|
type NativeMouseEvent = MouseEvent;
|
|
17
17
|
type NativeTouchEvent = TouchEvent;
|
|
18
18
|
type NativePointerEvent = PointerEvent;
|
|
19
|
-
type NativeSubmitEvent = SubmitEvent;
|
|
20
19
|
type NativeToggleEvent = ToggleEvent;
|
|
21
20
|
type NativeTransitionEvent = TransitionEvent;
|
|
22
21
|
type NativeUIEvent = UIEvent;
|
|
@@ -226,20 +225,12 @@ declare namespace React {
|
|
|
226
225
|
|
|
227
226
|
type ComponentState = any;
|
|
228
227
|
|
|
229
|
-
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES {}
|
|
230
|
-
|
|
231
228
|
/**
|
|
232
229
|
* A value which uniquely identifies a node among items in an array.
|
|
233
230
|
*
|
|
234
231
|
* @see {@link https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key React Docs}
|
|
235
232
|
*/
|
|
236
|
-
type Key =
|
|
237
|
-
| string
|
|
238
|
-
| number
|
|
239
|
-
| bigint
|
|
240
|
-
| DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES[
|
|
241
|
-
keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_KEY_TYPES
|
|
242
|
-
];
|
|
233
|
+
type Key = string | number | bigint;
|
|
243
234
|
|
|
244
235
|
/**
|
|
245
236
|
* @internal The props any component can receive.
|
|
@@ -1893,7 +1884,7 @@ declare namespace React {
|
|
|
1893
1884
|
*
|
|
1894
1885
|
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
|
|
1895
1886
|
*
|
|
1896
|
-
* @see
|
|
1887
|
+
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
|
|
1897
1888
|
*/
|
|
1898
1889
|
// NOTES
|
|
1899
1890
|
// - the order of these signatures matters - typescript will check the signatures in source order.
|
|
@@ -1935,31 +1926,7 @@ declare namespace React {
|
|
|
1935
1926
|
reducer: (state: State, action: Action) => State,
|
|
1936
1927
|
): [State, (action: Action) => void];
|
|
1937
1928
|
|
|
1938
|
-
|
|
1939
|
-
status?: void;
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
export interface PendingReactPromise<T> extends PromiseLike<T> {
|
|
1943
|
-
status: "pending";
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
export interface FulfilledReactPromise<T> extends PromiseLike<T> {
|
|
1947
|
-
status: "fulfilled";
|
|
1948
|
-
value: T;
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
export interface RejectedReactPromise<T> extends PromiseLike<T> {
|
|
1952
|
-
status: "rejected";
|
|
1953
|
-
reason: unknown;
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
export type ReactPromise<T> =
|
|
1957
|
-
| UntrackedReactPromise<T>
|
|
1958
|
-
| PendingReactPromise<T>
|
|
1959
|
-
| FulfilledReactPromise<T>
|
|
1960
|
-
| RejectedReactPromise<T>;
|
|
1961
|
-
|
|
1962
|
-
export type Usable<T> = ReactPromise<T> | Context<T>;
|
|
1929
|
+
export type Usable<T> = PromiseLike<T> | Context<T>;
|
|
1963
1930
|
|
|
1964
1931
|
export function use<T>(usable: Usable<T>): T;
|
|
1965
1932
|
|
|
@@ -2074,28 +2041,15 @@ declare namespace React {
|
|
|
2074
2041
|
target: EventTarget & Target;
|
|
2075
2042
|
}
|
|
2076
2043
|
|
|
2077
|
-
/**
|
|
2078
|
-
* @deprecated FormEvent doesn't actually exist.
|
|
2079
|
-
* You probably meant to use {@link ChangeEvent}, {@link InputEvent}, {@link SubmitEvent}, or just {@link SyntheticEvent} instead
|
|
2080
|
-
* depending on the event type.
|
|
2081
|
-
*/
|
|
2082
2044
|
interface FormEvent<T = Element> extends SyntheticEvent<T> {
|
|
2083
2045
|
}
|
|
2084
2046
|
|
|
2085
2047
|
interface InvalidEvent<T = Element> extends SyntheticEvent<T> {
|
|
2048
|
+
target: EventTarget & T;
|
|
2086
2049
|
}
|
|
2087
2050
|
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
* Only for form elements we know their target type because form events can't
|
|
2091
|
-
* be nested.
|
|
2092
|
-
* This type exists purely to narrow `target` for form elements. It doesn't
|
|
2093
|
-
* reflect a DOM event. Change events are just fired as standard {@link SyntheticEvent}.
|
|
2094
|
-
*/
|
|
2095
|
-
interface ChangeEvent<CurrentTarget = Element, Target = Element> extends SyntheticEvent<CurrentTarget> {
|
|
2096
|
-
// TODO: This is wrong for change event handlers on arbitrary. Should
|
|
2097
|
-
// be EventTarget & Target, but kept for backward compatibility until React 20.
|
|
2098
|
-
target: EventTarget & CurrentTarget;
|
|
2051
|
+
interface ChangeEvent<T = Element> extends SyntheticEvent<T> {
|
|
2052
|
+
target: EventTarget & T;
|
|
2099
2053
|
}
|
|
2100
2054
|
|
|
2101
2055
|
interface InputEvent<T = Element> extends SyntheticEvent<T, NativeInputEvent> {
|
|
@@ -2165,13 +2119,6 @@ declare namespace React {
|
|
|
2165
2119
|
shiftKey: boolean;
|
|
2166
2120
|
}
|
|
2167
2121
|
|
|
2168
|
-
interface SubmitEvent<T = Element> extends SyntheticEvent<T, NativeSubmitEvent> {
|
|
2169
|
-
// `submitter` is available in react@canary
|
|
2170
|
-
// submitter: HTMLElement | null;
|
|
2171
|
-
// SubmitEvents are always targetted at HTMLFormElements.
|
|
2172
|
-
target: EventTarget & HTMLFormElement;
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
2122
|
interface TouchEvent<T = Element> extends UIEvent<T, NativeTouchEvent> {
|
|
2176
2123
|
altKey: boolean;
|
|
2177
2124
|
changedTouches: TouchList;
|
|
@@ -2227,19 +2174,11 @@ declare namespace React {
|
|
|
2227
2174
|
type CompositionEventHandler<T = Element> = EventHandler<CompositionEvent<T>>;
|
|
2228
2175
|
type DragEventHandler<T = Element> = EventHandler<DragEvent<T>>;
|
|
2229
2176
|
type FocusEventHandler<T = Element> = EventHandler<FocusEvent<T>>;
|
|
2230
|
-
/**
|
|
2231
|
-
* @deprecated FormEventHandler doesn't actually exist.
|
|
2232
|
-
* You probably meant to use {@link ChangeEventHandler}, {@link InputEventHandler}, {@link SubmitEventHandler}, or just {@link EventHandler} instead
|
|
2233
|
-
* depending on the event type.
|
|
2234
|
-
*/
|
|
2235
2177
|
type FormEventHandler<T = Element> = EventHandler<FormEvent<T>>;
|
|
2236
|
-
type ChangeEventHandler<
|
|
2237
|
-
ChangeEvent<CurrentTarget, Target>
|
|
2238
|
-
>;
|
|
2178
|
+
type ChangeEventHandler<T = Element> = EventHandler<ChangeEvent<T>>;
|
|
2239
2179
|
type InputEventHandler<T = Element> = EventHandler<InputEvent<T>>;
|
|
2240
2180
|
type KeyboardEventHandler<T = Element> = EventHandler<KeyboardEvent<T>>;
|
|
2241
2181
|
type MouseEventHandler<T = Element> = EventHandler<MouseEvent<T>>;
|
|
2242
|
-
type SubmitEventHandler<T = Element> = EventHandler<SubmitEvent<T>>;
|
|
2243
2182
|
type TouchEventHandler<T = Element> = EventHandler<TouchEvent<T>>;
|
|
2244
2183
|
type PointerEventHandler<T = Element> = EventHandler<PointerEvent<T>>;
|
|
2245
2184
|
type UIEventHandler<T = Element> = EventHandler<UIEvent<T>>;
|
|
@@ -2293,19 +2232,19 @@ declare namespace React {
|
|
|
2293
2232
|
onBlur?: FocusEventHandler<T> | undefined;
|
|
2294
2233
|
onBlurCapture?: FocusEventHandler<T> | undefined;
|
|
2295
2234
|
|
|
2296
|
-
//
|
|
2297
|
-
onChange?:
|
|
2298
|
-
onChangeCapture?:
|
|
2235
|
+
// Form Events
|
|
2236
|
+
onChange?: FormEventHandler<T> | undefined;
|
|
2237
|
+
onChangeCapture?: FormEventHandler<T> | undefined;
|
|
2299
2238
|
onBeforeInput?: InputEventHandler<T> | undefined;
|
|
2300
|
-
onBeforeInputCapture?:
|
|
2301
|
-
onInput?:
|
|
2302
|
-
onInputCapture?:
|
|
2303
|
-
onReset?:
|
|
2304
|
-
onResetCapture?:
|
|
2305
|
-
onSubmit?:
|
|
2306
|
-
onSubmitCapture?:
|
|
2307
|
-
onInvalid?:
|
|
2308
|
-
onInvalidCapture?:
|
|
2239
|
+
onBeforeInputCapture?: FormEventHandler<T> | undefined;
|
|
2240
|
+
onInput?: FormEventHandler<T> | undefined;
|
|
2241
|
+
onInputCapture?: FormEventHandler<T> | undefined;
|
|
2242
|
+
onReset?: FormEventHandler<T> | undefined;
|
|
2243
|
+
onResetCapture?: FormEventHandler<T> | undefined;
|
|
2244
|
+
onSubmit?: FormEventHandler<T> | undefined;
|
|
2245
|
+
onSubmitCapture?: FormEventHandler<T> | undefined;
|
|
2246
|
+
onInvalid?: FormEventHandler<T> | undefined;
|
|
2247
|
+
onInvalidCapture?: FormEventHandler<T> | undefined;
|
|
2309
2248
|
|
|
2310
2249
|
// Image Events
|
|
2311
2250
|
onLoad?: ReactEventHandler<T> | undefined;
|
|
@@ -2849,7 +2788,7 @@ declare namespace React {
|
|
|
2849
2788
|
|
|
2850
2789
|
// Living Standard
|
|
2851
2790
|
/**
|
|
2852
|
-
* @see
|
|
2791
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert
|
|
2853
2792
|
*/
|
|
2854
2793
|
inert?: boolean | undefined;
|
|
2855
2794
|
/**
|
|
@@ -3312,9 +3251,7 @@ declare namespace React {
|
|
|
3312
3251
|
value?: string | readonly string[] | number | undefined;
|
|
3313
3252
|
width?: number | string | undefined;
|
|
3314
3253
|
|
|
3315
|
-
|
|
3316
|
-
// so we know the target will be a HTMLInputElement.
|
|
3317
|
-
onChange?: ChangeEventHandler<T, HTMLInputElement> | undefined;
|
|
3254
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3318
3255
|
}
|
|
3319
3256
|
|
|
3320
3257
|
interface KeygenHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3479,9 +3416,7 @@ declare namespace React {
|
|
|
3479
3416
|
required?: boolean | undefined;
|
|
3480
3417
|
size?: number | undefined;
|
|
3481
3418
|
value?: string | readonly string[] | number | undefined;
|
|
3482
|
-
|
|
3483
|
-
// so we know the target will be a HTMLSelectElement.
|
|
3484
|
-
onChange?: ChangeEventHandler<T, HTMLSelectElement> | undefined;
|
|
3419
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3485
3420
|
}
|
|
3486
3421
|
|
|
3487
3422
|
interface SourceHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3533,9 +3468,7 @@ declare namespace React {
|
|
|
3533
3468
|
value?: string | readonly string[] | number | undefined;
|
|
3534
3469
|
wrap?: string | undefined;
|
|
3535
3470
|
|
|
3536
|
-
|
|
3537
|
-
// so we know the target will be a HTMLTextAreaElement.
|
|
3538
|
-
onChange?: ChangeEventHandler<T, HTMLTextAreaElement> | undefined;
|
|
3471
|
+
onChange?: ChangeEventHandler<T> | undefined;
|
|
3539
3472
|
}
|
|
3540
3473
|
|
|
3541
3474
|
interface TdHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
@@ -3607,9 +3540,6 @@ declare namespace React {
|
|
|
3607
3540
|
method?: string | undefined;
|
|
3608
3541
|
min?: number | string | undefined;
|
|
3609
3542
|
name?: string | undefined;
|
|
3610
|
-
nonce?: string | undefined;
|
|
3611
|
-
part?: string | undefined;
|
|
3612
|
-
slot?: string | undefined;
|
|
3613
3543
|
style?: CSSProperties | undefined;
|
|
3614
3544
|
target?: string | undefined;
|
|
3615
3545
|
type?: string | undefined;
|
|
@@ -4127,6 +4057,7 @@ declare namespace React {
|
|
|
4127
4057
|
* Captures which component contained the exception, and its ancestors.
|
|
4128
4058
|
*/
|
|
4129
4059
|
componentStack?: string | null;
|
|
4060
|
+
digest?: string | null;
|
|
4130
4061
|
}
|
|
4131
4062
|
|
|
4132
4063
|
// Keep in sync with JSX namespace in ./jsx-runtime.d.ts and ./jsx-dev-runtime.d.ts
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// See https://github.com/facebook/react/blob/main/packages/react-dom/client.js to see how the exports are declared,
|
|
6
6
|
|
|
7
|
-
import React = require("https://esm.sh/@types/react@19.2.
|
|
7
|
+
import React = require("https://esm.sh/@types/react@19.2.3/index.d.ts");
|
|
8
8
|
|
|
9
9
|
export {};
|
|
10
10
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const RESEARCH_TASK_CUE_PATTERN = /\b(research|report|findings|sources|authoritative sources)\b/i;
|
|
2
|
+
const RESEARCH_PROJECT_SAVE_CUE_PATTERN =
|
|
3
|
+
/\b(?:save|write|persist|store|compile)\b[^\n]{0,120}\b(?:to|into)\b[^\n]{0,40}\b(?:the\s+)?project\b/i;
|
|
4
|
+
|
|
5
|
+
const PROJECT_ARTIFACT_PATH_PATTERN = /(?:\/|\.{1,2}\/)?(?:[\w.-]+\/)+[\w.-]+\.[\w.-]+/g;
|
|
6
|
+
|
|
7
|
+
function slugifyArtifactSegment(value: string): string {
|
|
8
|
+
return value
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/['"]/g, "")
|
|
11
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
12
|
+
.replace(/^-+|-+$/g, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function slugifyRunArtifactSegment(value: string): string {
|
|
16
|
+
return value
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
19
|
+
.replace(/^-+|-+$/g, "");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasAnyArtifactPath(prompt: string): boolean {
|
|
23
|
+
PROJECT_ARTIFACT_PATH_PATTERN.lastIndex = 0;
|
|
24
|
+
return PROJECT_ARTIFACT_PATH_PATTERN.test(prompt);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isGenericResearchTopic(value: string): boolean {
|
|
28
|
+
const normalized = value.trim().toLowerCase();
|
|
29
|
+
return normalized.length === 0 ||
|
|
30
|
+
normalized === "this" ||
|
|
31
|
+
normalized === "that" ||
|
|
32
|
+
normalized === "it" ||
|
|
33
|
+
normalized === "the project" ||
|
|
34
|
+
normalized === "the topic";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractResearchTopic(input: { description: string; prompt: string }): string | null {
|
|
38
|
+
const quotedPromptTopic = input.prompt.match(/\bresearch(?:\s+on|\s+about)?\s+["“]([^"”]+)["”]/i)
|
|
39
|
+
?.[1];
|
|
40
|
+
if (quotedPromptTopic?.trim() && !isGenericResearchTopic(quotedPromptTopic)) {
|
|
41
|
+
return quotedPromptTopic.trim();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cleanedDescription = input.description
|
|
45
|
+
.replace(/^research\s+/i, "")
|
|
46
|
+
.replace(/\.\s+.*$/s, "")
|
|
47
|
+
.replace(/\s+and\s+(?:save|write|persist|store|compile)\b.*$/i, "")
|
|
48
|
+
.replace(/\s+across\b.*$/i, "")
|
|
49
|
+
.trim();
|
|
50
|
+
if (cleanedDescription.length > 0) {
|
|
51
|
+
return cleanedDescription;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const promptTopic = input.prompt
|
|
55
|
+
.match(/\bresearch(?:\s+on|\s+about)?\s+([^\n.,:]+)/i)?.[1]
|
|
56
|
+
?.replace(/\s+and\s+save\b.*$/i, "")
|
|
57
|
+
?.replace(/\s+and\s+write\b.*$/i, "")
|
|
58
|
+
?.trim();
|
|
59
|
+
if (!promptTopic || isGenericResearchTopic(promptTopic)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return promptTopic;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface DefaultResearchArtifactPaths {
|
|
67
|
+
topicSlug: string;
|
|
68
|
+
topicRootPath: string;
|
|
69
|
+
currentReportPath: string;
|
|
70
|
+
runReportPath: string;
|
|
71
|
+
findingsPath: string;
|
|
72
|
+
sourcesPath: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function shouldInjectDefaultResearchArtifactPath(input: {
|
|
76
|
+
description: string;
|
|
77
|
+
prompt: string;
|
|
78
|
+
}): boolean {
|
|
79
|
+
if (
|
|
80
|
+
!RESEARCH_TASK_CUE_PATTERN.test(input.description) &&
|
|
81
|
+
!RESEARCH_TASK_CUE_PATTERN.test(input.prompt)
|
|
82
|
+
) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!RESEARCH_PROJECT_SAVE_CUE_PATTERN.test(input.prompt)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return !hasAnyArtifactPath(input.prompt);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function buildDefaultResearchArtifactPathReminder(input: {
|
|
94
|
+
description: string;
|
|
95
|
+
prompt: string;
|
|
96
|
+
runId?: string;
|
|
97
|
+
}): string | null {
|
|
98
|
+
if (!shouldInjectDefaultResearchArtifactPath(input)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const artifactPaths = buildDefaultResearchArtifactPaths(input);
|
|
103
|
+
|
|
104
|
+
return [
|
|
105
|
+
"Default research workspace (because no exact artifact path was provided):",
|
|
106
|
+
`- Write the run-scoped report to exactly ${artifactPaths.runReportPath}.`,
|
|
107
|
+
`- Then create or update the current topic report at exactly ${artifactPaths.currentReportPath}.`,
|
|
108
|
+
`- Supporting artifacts can live at ${artifactPaths.findingsPath} and ${artifactPaths.sourcesPath} when useful.`,
|
|
109
|
+
`CRITICAL: The task is incomplete until ${artifactPaths.runReportPath} and ${artifactPaths.currentReportPath} both exist with the final report content.`,
|
|
110
|
+
"Use create_file or update_file yourself before finishing.",
|
|
111
|
+
].join("\n");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function buildDefaultResearchArtifactPaths(input: {
|
|
115
|
+
description: string;
|
|
116
|
+
prompt: string;
|
|
117
|
+
runId?: string;
|
|
118
|
+
}): DefaultResearchArtifactPaths {
|
|
119
|
+
const topic = extractResearchTopic(input);
|
|
120
|
+
const topicSlug = topic ? slugifyArtifactSegment(topic) : "research-report";
|
|
121
|
+
const sanitizedRunId = slugifyRunArtifactSegment(input.runId ?? "");
|
|
122
|
+
const effectiveRunId = sanitizedRunId.length > 0 ? sanitizedRunId : "latest";
|
|
123
|
+
const topicRootPath = `/research/${topicSlug}`;
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
topicSlug,
|
|
127
|
+
topicRootPath,
|
|
128
|
+
currentReportPath: `${topicRootPath}/report.md`,
|
|
129
|
+
runReportPath: `${topicRootPath}/runs/${effectiveRunId}.report.md`,
|
|
130
|
+
findingsPath: `${topicRootPath}/findings.md`,
|
|
131
|
+
sourcesPath: `${topicRootPath}/sources.md`,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function withDefaultResearchArtifactPath(input: {
|
|
136
|
+
description: string;
|
|
137
|
+
prompt: string;
|
|
138
|
+
runId?: string;
|
|
139
|
+
}): string {
|
|
140
|
+
const reminder = buildDefaultResearchArtifactPathReminder(input);
|
|
141
|
+
if (!reminder) {
|
|
142
|
+
return input.prompt;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return [input.prompt, "", reminder].join("\n");
|
|
146
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import type { ChatSystemMessage } from "../chat/types.js";
|
|
2
|
+
import { isHostedChildCreateFileAlreadyExistsResult } from "./hosted-child-artifact-support.js";
|
|
3
|
+
import {
|
|
4
|
+
buildDefaultResearchArtifactPathReminder,
|
|
5
|
+
buildDefaultResearchArtifactPaths,
|
|
6
|
+
type DefaultResearchArtifactPaths,
|
|
7
|
+
} from "./default-research-artifact-policy.js";
|
|
8
|
+
|
|
9
|
+
export type DefaultResearchArtifacts = DefaultResearchArtifactPaths;
|
|
10
|
+
|
|
11
|
+
export interface DefaultResearchArtifactContext {
|
|
12
|
+
availableToolNames?: string[];
|
|
13
|
+
parentRunId?: string;
|
|
14
|
+
defaultResearchArtifacts?: DefaultResearchArtifacts | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DefaultResearchArtifactLogger {
|
|
18
|
+
debug?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function extractLatestUserText(messages: readonly unknown[]): string | null {
|
|
26
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
27
|
+
const message = messages[index];
|
|
28
|
+
if (!isRecord(message) || message.role !== "user") {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const content = message.content;
|
|
33
|
+
if (typeof content === "string" && content.trim().length > 0) {
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!Array.isArray(content)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const text = content
|
|
42
|
+
.flatMap((part) =>
|
|
43
|
+
isRecord(part) && part.type === "text" && typeof part.text === "string"
|
|
44
|
+
? [part.text.trim()]
|
|
45
|
+
: []
|
|
46
|
+
)
|
|
47
|
+
.filter((value) => value.length > 0)
|
|
48
|
+
.join("\n");
|
|
49
|
+
|
|
50
|
+
if (text.length > 0) {
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function extractLatestUserDescription(text: string): string {
|
|
59
|
+
const withoutCommandSpan = text.replace(
|
|
60
|
+
/<span\s+data-command="[^"]+">\s*(\/[a-z0-9_-]+)\s*<\/span>/gi,
|
|
61
|
+
"$1",
|
|
62
|
+
);
|
|
63
|
+
const withoutLeadingSlashCommand = withoutCommandSpan.replace(/^\s*\/[a-z0-9_-]+\s*/i, "");
|
|
64
|
+
|
|
65
|
+
return withoutLeadingSlashCommand.trim();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function fetchLatestConversationUserText(input: {
|
|
69
|
+
apiUrl: string;
|
|
70
|
+
authToken: string;
|
|
71
|
+
conversationId?: string;
|
|
72
|
+
logger?: DefaultResearchArtifactLogger;
|
|
73
|
+
}): Promise<string | null> {
|
|
74
|
+
if (!input.conversationId) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(
|
|
80
|
+
`${input.apiUrl}/conversations/${input.conversationId}/messages?limit=20`,
|
|
81
|
+
{
|
|
82
|
+
headers: {
|
|
83
|
+
Authorization: `Bearer ${input.authToken}`,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
input.logger?.debug?.(
|
|
90
|
+
"Could not preload conversation messages for research workspace detection",
|
|
91
|
+
{
|
|
92
|
+
conversationId: input.conversationId,
|
|
93
|
+
status: response.status,
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const payload = await response.json();
|
|
100
|
+
const data = isRecord(payload) ? payload.data : undefined;
|
|
101
|
+
const messages = Array.isArray(data)
|
|
102
|
+
? data.map((message) => ({
|
|
103
|
+
role: isRecord(message) ? message.role : undefined,
|
|
104
|
+
content: isRecord(message) && Array.isArray(message.parts) ? message.parts : [],
|
|
105
|
+
}))
|
|
106
|
+
: [];
|
|
107
|
+
|
|
108
|
+
return extractLatestUserText(messages);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
input.logger?.debug?.(
|
|
111
|
+
"Failed to preload conversation messages for research workspace detection",
|
|
112
|
+
{
|
|
113
|
+
conversationId: input.conversationId,
|
|
114
|
+
error,
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function updateDefaultResearchArtifacts(input: {
|
|
122
|
+
taskContext: DefaultResearchArtifactContext;
|
|
123
|
+
latestUserText: string | null;
|
|
124
|
+
system: string | ChatSystemMessage[];
|
|
125
|
+
}): string | ChatSystemMessage[] {
|
|
126
|
+
if (!input.latestUserText) {
|
|
127
|
+
return input.system;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const latestUserDescription = extractLatestUserDescription(input.latestUserText);
|
|
131
|
+
const defaultResearchWorkspaceReminder = buildDefaultResearchArtifactPathReminder({
|
|
132
|
+
description: latestUserDescription,
|
|
133
|
+
prompt: input.latestUserText,
|
|
134
|
+
runId: input.taskContext.parentRunId,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (!defaultResearchWorkspaceReminder) {
|
|
138
|
+
input.taskContext.defaultResearchArtifacts = null;
|
|
139
|
+
return input.system;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
input.taskContext.defaultResearchArtifacts = buildDefaultResearchArtifactPaths({
|
|
143
|
+
description: latestUserDescription,
|
|
144
|
+
prompt: input.latestUserText,
|
|
145
|
+
runId: input.taskContext.parentRunId,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return appendSystemReminder(input.system, defaultResearchWorkspaceReminder);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function appendSystemReminder(
|
|
152
|
+
instructions: string | ChatSystemMessage[],
|
|
153
|
+
reminder: string,
|
|
154
|
+
): string | ChatSystemMessage[] {
|
|
155
|
+
if (typeof instructions === "string") {
|
|
156
|
+
return instructions.includes(reminder) ? instructions : `${instructions}\n\n${reminder}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (instructions.some((message) => message.content.includes(reminder))) {
|
|
160
|
+
return instructions;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return [
|
|
164
|
+
...instructions,
|
|
165
|
+
{
|
|
166
|
+
role: "system",
|
|
167
|
+
content: reminder,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function applyDefaultResearchArtifactPath(
|
|
173
|
+
toolName: string,
|
|
174
|
+
toolInput: Record<string, unknown>,
|
|
175
|
+
taskContext: DefaultResearchArtifactContext,
|
|
176
|
+
): Record<string, unknown> {
|
|
177
|
+
const defaultArtifacts = taskContext.defaultResearchArtifacts;
|
|
178
|
+
if (!defaultArtifacts || (toolName !== "create_file" && toolName !== "update_file")) {
|
|
179
|
+
return toolInput;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const path = typeof toolInput.path === "string" ? toolInput.path.replace(/^\/+/, "") : null;
|
|
183
|
+
if (!path) {
|
|
184
|
+
return toolInput;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const canonicalCurrentPath = defaultArtifacts.currentReportPath.replace(/^\/+/, "");
|
|
188
|
+
const canonicalRunPath = defaultArtifacts.runReportPath.replace(/^\/+/, "");
|
|
189
|
+
const canonicalFindingsPath = defaultArtifacts.findingsPath.replace(/^\/+/, "");
|
|
190
|
+
const canonicalSourcesPath = defaultArtifacts.sourcesPath.replace(/^\/+/, "");
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
path === canonicalCurrentPath || path === canonicalRunPath || path === canonicalFindingsPath ||
|
|
194
|
+
path === canonicalSourcesPath
|
|
195
|
+
) {
|
|
196
|
+
return toolInput;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!path.endsWith("/report.md") && path !== "report.md") {
|
|
200
|
+
return toolInput;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...toolInput,
|
|
205
|
+
path: canonicalCurrentPath,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function shouldRetryCreateResearchArtifactAsUpdate(input: {
|
|
210
|
+
toolName: string;
|
|
211
|
+
toolInput: Record<string, unknown>;
|
|
212
|
+
taskContext: DefaultResearchArtifactContext;
|
|
213
|
+
error: unknown;
|
|
214
|
+
}): boolean {
|
|
215
|
+
if (input.toolName !== "create_file") {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const defaultArtifacts = input.taskContext.defaultResearchArtifacts;
|
|
220
|
+
if (!isHostedChildCreateFileAlreadyExistsResult(input.error)) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const path = typeof input.toolInput.path === "string"
|
|
225
|
+
? input.toolInput.path.replace(/^\/+/, "")
|
|
226
|
+
: null;
|
|
227
|
+
const content = typeof input.toolInput.content === "string" ? input.toolInput.content : null;
|
|
228
|
+
if (!path || !content) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!defaultArtifacts) {
|
|
233
|
+
return path.startsWith("research/") && path.endsWith(".md");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const topicRootPath = defaultArtifacts.currentReportPath.replace(/^\/+/, "").replace(
|
|
237
|
+
/\/report\.md$/,
|
|
238
|
+
"",
|
|
239
|
+
);
|
|
240
|
+
return path === topicRootPath || path.startsWith(`${topicRootPath}/`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export async function mirrorDefaultResearchRunArtifact(input: {
|
|
244
|
+
toolName: string;
|
|
245
|
+
toolInput: Record<string, unknown>;
|
|
246
|
+
taskContext: DefaultResearchArtifactContext;
|
|
247
|
+
activeProjectId: string | null;
|
|
248
|
+
executeContext: Record<string, unknown> | undefined;
|
|
249
|
+
executeTool: (
|
|
250
|
+
toolName: string,
|
|
251
|
+
args: Record<string, unknown>,
|
|
252
|
+
context: Record<string, unknown> | undefined,
|
|
253
|
+
) => Promise<unknown>;
|
|
254
|
+
}): Promise<void> {
|
|
255
|
+
const defaultArtifacts = input.taskContext.defaultResearchArtifacts;
|
|
256
|
+
if (!defaultArtifacts || (input.toolName !== "create_file" && input.toolName !== "update_file")) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const content = typeof input.toolInput.content === "string" ? input.toolInput.content : null;
|
|
261
|
+
const path = typeof input.toolInput.path === "string"
|
|
262
|
+
? input.toolInput.path.replace(/^\/+/, "")
|
|
263
|
+
: null;
|
|
264
|
+
const canonicalCurrentPath = defaultArtifacts.currentReportPath.replace(/^\/+/, "");
|
|
265
|
+
const canonicalRunPath = defaultArtifacts.runReportPath.replace(/^\/+/, "");
|
|
266
|
+
|
|
267
|
+
if (!content || path !== canonicalCurrentPath) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const mirroredInput: Record<string, unknown> = {
|
|
272
|
+
...input.toolInput,
|
|
273
|
+
path: canonicalRunPath,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
if (input.activeProjectId) {
|
|
277
|
+
mirroredInput.project_reference = input.activeProjectId;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
await input.executeTool(input.toolName, mirroredInput, input.executeContext);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (input.toolName === "create_file" && isHostedChildCreateFileAlreadyExistsResult(error)) {
|
|
284
|
+
await input.executeTool("update_file", mirroredInput, input.executeContext);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}
|