@unieai/rabi-tool-session-query 0.0.0-stage → 0.2.2-rc.5
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/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/index.js +1033 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/input.d.ts +170 -0
- package/lib/types/operations.d.ts +45 -0
- package/lib/types/presentation.d.ts +53 -0
- package/lib/types/service-boundary.d.ts +18 -0
- package/lib/types/workspace-access.d.ts +63 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +42 -4
- package/src/index.ts +136 -0
- package/src/input.ts +307 -0
- package/src/operations.ts +280 -0
- package/src/presentation.ts +255 -0
- package/src/service-boundary.ts +179 -0
- package/src/workspace-access.ts +256 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing, workspace-authorized session-history search and read tools.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@unieai/cordis';
|
|
7
|
+
import z from '@unieai/schemastery';
|
|
8
|
+
/** Cordis plugin name used by Loader diagnostics. */
|
|
9
|
+
export declare const name = "tool-session-query";
|
|
10
|
+
/** Capability services required by the model-facing consumer. */
|
|
11
|
+
export declare const inject: string[];
|
|
12
|
+
/** Default maximum number of authorized search hits returned by one call. */
|
|
13
|
+
export declare const DEFAULT_MAX_SEARCH_RESULTS = 100;
|
|
14
|
+
/** Default cooperative deadline for either full-text search tool. */
|
|
15
|
+
export declare const DEFAULT_SEARCH_TIMEOUT_MS = 30000;
|
|
16
|
+
/** Deployment-owned search count and timeout bounds. */
|
|
17
|
+
export interface Config {
|
|
18
|
+
/** Maximum authorized hits returned by one search call. Defaults to 100. */
|
|
19
|
+
maxSearchResults?: number;
|
|
20
|
+
/** Cooperative full-text search deadline in milliseconds. Defaults to 30000. */
|
|
21
|
+
searchTimeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Schemastery config for Loader defaults and generated configuration docs. */
|
|
24
|
+
export declare const Config: z<Config>;
|
|
25
|
+
/** Register all five tools and their shared model guidance. */
|
|
26
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model argument schemas, normalization, and filter construction.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query/input
|
|
5
|
+
*/
|
|
6
|
+
import { type SessionId as SessionIdValue } from '@unieai/rabi-session';
|
|
7
|
+
import { type SessionAvailability, type SessionEventMetadataFilter, type SessionEventSurface, type SessionResultFilter } from '@unieai/rabi-session-query';
|
|
8
|
+
interface SessionSearchArgs {
|
|
9
|
+
query: string;
|
|
10
|
+
session_ids?: string[];
|
|
11
|
+
created_at_from?: string;
|
|
12
|
+
created_at_to?: string;
|
|
13
|
+
parent_session_ids?: string[];
|
|
14
|
+
include_root_sessions?: boolean;
|
|
15
|
+
availability?: SessionAvailability[];
|
|
16
|
+
event_seq_from?: number;
|
|
17
|
+
event_seq_to?: number;
|
|
18
|
+
event_time_from?: string;
|
|
19
|
+
event_time_to?: string;
|
|
20
|
+
event_types?: string[];
|
|
21
|
+
event_surfaces?: SessionEventSurface[];
|
|
22
|
+
}
|
|
23
|
+
interface EventFilterInput {
|
|
24
|
+
readonly seqFrom?: number | undefined;
|
|
25
|
+
readonly seqTo?: number | undefined;
|
|
26
|
+
readonly timeFrom?: string | undefined;
|
|
27
|
+
readonly timeTo?: string | undefined;
|
|
28
|
+
readonly eventTypes?: string[] | undefined;
|
|
29
|
+
readonly surfaces?: SessionEventSurface[] | undefined;
|
|
30
|
+
}
|
|
31
|
+
declare function buildSessionFilters(args: SessionSearchArgs): SessionResultFilter[];
|
|
32
|
+
declare function materializeParentSessionIds(values: readonly string[] | undefined): SessionIdValue[] | undefined;
|
|
33
|
+
declare function buildEventFilters(input: EventFilterInput): SessionEventMetadataFilter[];
|
|
34
|
+
declare function normalizeQuery(value: string): string;
|
|
35
|
+
declare function sequenceRange(from: number | undefined, to: number | undefined): {
|
|
36
|
+
from?: number;
|
|
37
|
+
to?: number;
|
|
38
|
+
};
|
|
39
|
+
declare function assertNonNegativeSafeInteger(name: string, value: number): void;
|
|
40
|
+
/** Model schemas and model-owned value normalization shared by tool operations. */
|
|
41
|
+
export declare const toolInput: {
|
|
42
|
+
sessionSearchParameters: {
|
|
43
|
+
readonly query: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
readonly required: true;
|
|
46
|
+
readonly description: "Literal full-text query over prior session history.";
|
|
47
|
+
};
|
|
48
|
+
readonly session_ids: {
|
|
49
|
+
readonly type: "array";
|
|
50
|
+
readonly items: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
};
|
|
53
|
+
readonly description: "Optional session ids to include.";
|
|
54
|
+
};
|
|
55
|
+
readonly created_at_from: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 creation-time lower bound.";
|
|
58
|
+
};
|
|
59
|
+
readonly created_at_to: {
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 creation-time upper bound.";
|
|
62
|
+
};
|
|
63
|
+
readonly parent_session_ids: {
|
|
64
|
+
readonly type: "array";
|
|
65
|
+
readonly items: {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
};
|
|
68
|
+
readonly description: "Optional direct parent session ids.";
|
|
69
|
+
};
|
|
70
|
+
readonly include_root_sessions: {
|
|
71
|
+
readonly type: "boolean";
|
|
72
|
+
readonly description: "Include sessions with no parent in the parent filter.";
|
|
73
|
+
};
|
|
74
|
+
readonly availability: {
|
|
75
|
+
readonly type: "array";
|
|
76
|
+
readonly items: {
|
|
77
|
+
readonly type: "string";
|
|
78
|
+
readonly enum: readonly ["live", "persisted"];
|
|
79
|
+
};
|
|
80
|
+
readonly description: "Require at least one selected source availability.";
|
|
81
|
+
};
|
|
82
|
+
readonly event_seq_from: {
|
|
83
|
+
readonly type: "integer";
|
|
84
|
+
readonly description: "Inclusive event sequence lower bound.";
|
|
85
|
+
};
|
|
86
|
+
readonly event_seq_to: {
|
|
87
|
+
readonly type: "integer";
|
|
88
|
+
readonly description: "Inclusive event sequence upper bound.";
|
|
89
|
+
};
|
|
90
|
+
readonly event_time_from: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 event-time lower bound.";
|
|
93
|
+
};
|
|
94
|
+
readonly event_time_to: {
|
|
95
|
+
readonly type: "string";
|
|
96
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 event-time upper bound.";
|
|
97
|
+
};
|
|
98
|
+
readonly event_types: {
|
|
99
|
+
readonly type: "array";
|
|
100
|
+
readonly items: {
|
|
101
|
+
readonly type: "string";
|
|
102
|
+
};
|
|
103
|
+
readonly description: "Event types to include.";
|
|
104
|
+
};
|
|
105
|
+
readonly event_surfaces: {
|
|
106
|
+
readonly type: "array";
|
|
107
|
+
readonly items: {
|
|
108
|
+
readonly type: "string";
|
|
109
|
+
readonly enum: readonly ["current", "shadowed", "log-only"];
|
|
110
|
+
};
|
|
111
|
+
readonly description: "Event surfaces to include.";
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
eventSearchParameters: {
|
|
115
|
+
readonly session_id: {
|
|
116
|
+
readonly type: "string";
|
|
117
|
+
readonly description: "Target session id. Omit for the current session.";
|
|
118
|
+
};
|
|
119
|
+
readonly query: {
|
|
120
|
+
readonly type: "string";
|
|
121
|
+
readonly required: true;
|
|
122
|
+
readonly description: "Literal full-text query over the target session.";
|
|
123
|
+
};
|
|
124
|
+
readonly seq_from: {
|
|
125
|
+
readonly type: "integer";
|
|
126
|
+
readonly description: "Inclusive event sequence lower bound.";
|
|
127
|
+
};
|
|
128
|
+
readonly seq_to: {
|
|
129
|
+
readonly type: "integer";
|
|
130
|
+
readonly description: "Inclusive event sequence upper bound.";
|
|
131
|
+
};
|
|
132
|
+
readonly time_from: {
|
|
133
|
+
readonly type: "string";
|
|
134
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 event-time lower bound.";
|
|
135
|
+
};
|
|
136
|
+
readonly time_to: {
|
|
137
|
+
readonly type: "string";
|
|
138
|
+
readonly description: "Inclusive timezone-qualified ISO 8601 event-time upper bound.";
|
|
139
|
+
};
|
|
140
|
+
readonly event_types: {
|
|
141
|
+
readonly type: "array";
|
|
142
|
+
readonly items: {
|
|
143
|
+
readonly type: "string";
|
|
144
|
+
};
|
|
145
|
+
readonly description: "Event types to include.";
|
|
146
|
+
};
|
|
147
|
+
readonly surfaces: {
|
|
148
|
+
readonly type: "array";
|
|
149
|
+
readonly items: {
|
|
150
|
+
readonly type: "string";
|
|
151
|
+
readonly enum: readonly ["current", "shadowed", "log-only"];
|
|
152
|
+
};
|
|
153
|
+
readonly description: "Event surfaces to include.";
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
targetSessionParameter: {
|
|
157
|
+
readonly session_id: {
|
|
158
|
+
readonly type: "string";
|
|
159
|
+
readonly description: "Target session id. Omit for the current session.";
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
buildSessionFilters: typeof buildSessionFilters;
|
|
163
|
+
materializeParentSessionIds: typeof materializeParentSessionIds;
|
|
164
|
+
buildEventFilters: typeof buildEventFilters;
|
|
165
|
+
normalizeQuery: typeof normalizeQuery;
|
|
166
|
+
sequenceRange: typeof sequenceRange;
|
|
167
|
+
assertNonNegativeSafeInteger: typeof assertNonNegativeSafeInteger;
|
|
168
|
+
};
|
|
169
|
+
export {};
|
|
170
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool operation orchestration over session-query service capabilities.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query/operations
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@unieai/cordis';
|
|
7
|
+
import { type SessionEventSurface } from '@unieai/rabi-session-query';
|
|
8
|
+
import type { ToolRunContext } from '@unieai/rabi-tools';
|
|
9
|
+
import { toolInput } from './input.ts';
|
|
10
|
+
type SessionSearchArgs = Parameters<typeof toolInput.buildSessionFilters>[0];
|
|
11
|
+
interface EventSearchArgs {
|
|
12
|
+
session_id?: string;
|
|
13
|
+
query: string;
|
|
14
|
+
seq_from?: number;
|
|
15
|
+
seq_to?: number;
|
|
16
|
+
time_from?: string;
|
|
17
|
+
time_to?: string;
|
|
18
|
+
event_types?: string[];
|
|
19
|
+
surfaces?: SessionEventSurface[];
|
|
20
|
+
}
|
|
21
|
+
interface SessionTargetArgs {
|
|
22
|
+
session_id?: string;
|
|
23
|
+
}
|
|
24
|
+
interface EventTargetArgs extends SessionTargetArgs {
|
|
25
|
+
seq: number;
|
|
26
|
+
}
|
|
27
|
+
interface EventReadArgs extends EventTargetArgs {
|
|
28
|
+
before?: number;
|
|
29
|
+
after?: number;
|
|
30
|
+
}
|
|
31
|
+
declare function executeSessionSearch(ctx: Context, args: SessionSearchArgs, exec: ToolRunContext, maxResults: number): Promise<string>;
|
|
32
|
+
declare function executeEventSearch(ctx: Context, args: EventSearchArgs, exec: ToolRunContext, maxResults: number): Promise<string>;
|
|
33
|
+
declare function executeSessionTrace(ctx: Context, args: SessionTargetArgs, exec: ToolRunContext): Promise<string>;
|
|
34
|
+
declare function executeEventTrace(ctx: Context, args: EventTargetArgs, exec: ToolRunContext): Promise<string>;
|
|
35
|
+
declare function executeEventRead(ctx: Context, args: EventReadArgs, exec: ToolRunContext): Promise<string>;
|
|
36
|
+
/** Five model-facing session-query operation implementations. */
|
|
37
|
+
export declare const operations: {
|
|
38
|
+
executeSessionSearch: typeof executeSessionSearch;
|
|
39
|
+
executeEventSearch: typeof executeEventSearch;
|
|
40
|
+
executeSessionTrace: typeof executeSessionTrace;
|
|
41
|
+
executeEventTrace: typeof executeEventTrace;
|
|
42
|
+
executeEventRead: typeof executeEventRead;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model text rendering and generic tool-call presentation.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query/presentation
|
|
5
|
+
*/
|
|
6
|
+
import { type SessionEventSearchHit, type SessionEventTraceObservation, type SessionEventWindow, type SessionLineageTrace, type SessionRecord, type SessionSearchHit } from '@unieai/rabi-session-query';
|
|
7
|
+
import type { SessionId } from '@unieai/rabi-session';
|
|
8
|
+
import type { GenericCallView } from '@unieai/rabi-tools';
|
|
9
|
+
import { workspaceAccess } from './workspace-access.ts';
|
|
10
|
+
type TitleView = Awaited<ReturnType<typeof workspaceAccess.readTitle>>;
|
|
11
|
+
type CompleteTitleMap = Awaited<ReturnType<typeof workspaceAccess.readTitles>>;
|
|
12
|
+
type AuthorizedDescendants = ReturnType<typeof workspaceAccess.authorizeDescendants>;
|
|
13
|
+
interface SearchCollection<T> {
|
|
14
|
+
readonly items: T[];
|
|
15
|
+
readonly capped: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface SessionSearchCallArgs {
|
|
18
|
+
readonly query: string;
|
|
19
|
+
}
|
|
20
|
+
interface EventSearchCallArgs {
|
|
21
|
+
readonly query: string;
|
|
22
|
+
}
|
|
23
|
+
interface SessionTargetCallArgs {
|
|
24
|
+
readonly session_id?: string;
|
|
25
|
+
}
|
|
26
|
+
interface EventTargetCallArgs extends SessionTargetCallArgs {
|
|
27
|
+
readonly seq: number;
|
|
28
|
+
}
|
|
29
|
+
declare function formatSessionSearch(collected: SearchCollection<SessionSearchHit>, titles: CompleteTitleMap, authorizedParents: ReadonlySet<SessionId>): string;
|
|
30
|
+
declare function formatEmptySessionSearch(): string;
|
|
31
|
+
declare function formatEventSearch(sessionId: SessionId, title: TitleView, collected: SearchCollection<SessionEventSearchHit>): string;
|
|
32
|
+
declare function formatSessionTrace(trace: SessionLineageTrace, ancestors: readonly SessionRecord[], ancestorBoundary: boolean, descendants: AuthorizedDescendants, titles: CompleteTitleMap): string;
|
|
33
|
+
declare function formatEventTrace(sessionId: SessionId, title: TitleView, trace: SessionEventTraceObservation): string;
|
|
34
|
+
declare function formatEventRead(sessionId: SessionId, title: TitleView, window: SessionEventWindow): string;
|
|
35
|
+
declare function presentSessionSearchCall(args: SessionSearchCallArgs): GenericCallView;
|
|
36
|
+
declare function presentEventSearchCall(args: EventSearchCallArgs): GenericCallView;
|
|
37
|
+
declare function presentSessionTraceCall(args: SessionTargetCallArgs): GenericCallView;
|
|
38
|
+
declare function presentEventTargetCall(action: string, args: EventTargetCallArgs): GenericCallView;
|
|
39
|
+
/** Text output and call-card presentation for every session-query tool. */
|
|
40
|
+
export declare const presentation: {
|
|
41
|
+
formatSessionSearch: typeof formatSessionSearch;
|
|
42
|
+
formatEmptySessionSearch: typeof formatEmptySessionSearch;
|
|
43
|
+
formatEventSearch: typeof formatEventSearch;
|
|
44
|
+
formatSessionTrace: typeof formatSessionTrace;
|
|
45
|
+
formatEventTrace: typeof formatEventTrace;
|
|
46
|
+
formatEventRead: typeof formatEventRead;
|
|
47
|
+
presentSessionSearchCall: typeof presentSessionSearchCall;
|
|
48
|
+
presentEventSearchCall: typeof presentEventSearchCall;
|
|
49
|
+
presentSessionTraceCall: typeof presentSessionTraceCall;
|
|
50
|
+
presentEventTargetCall: typeof presentEventTargetCall;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=presentation.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-query service error containment and model-safe translation.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query/service-boundary
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@unieai/cordis';
|
|
7
|
+
import { HarnessError } from '@unieai/rabi-llm';
|
|
8
|
+
declare function unauthorizedTarget(): HarnessError;
|
|
9
|
+
declare function call<Value>(ctx: Context, signal: AbortSignal, operation: string, invoke: () => Promise<Value>): Promise<Value>;
|
|
10
|
+
declare function sanitizeError(ctx: Context, operation: string, error: unknown): HarnessError;
|
|
11
|
+
/** Model-safe session-query invocation and error translation boundary. */
|
|
12
|
+
export declare const serviceBoundary: {
|
|
13
|
+
unauthorizedTarget: typeof unauthorizedTarget;
|
|
14
|
+
call: typeof call;
|
|
15
|
+
sanitizeError: typeof sanitizeError;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=service-boundary.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caller identity, workspace authorization, and visible lineage projection.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query/workspace-access
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@unieai/cordis';
|
|
7
|
+
import { type SessionHeader, type SessionId as SessionIdValue } from '@unieai/rabi-session';
|
|
8
|
+
import type { TurnBoundaryProjection } from '@unieai/rabi-agent';
|
|
9
|
+
import type { SessionLineageNode, SessionRecord } from '@unieai/rabi-session-query';
|
|
10
|
+
import type { ToolRunContext } from '@unieai/rabi-tools';
|
|
11
|
+
interface Caller {
|
|
12
|
+
readonly id: SessionIdValue;
|
|
13
|
+
readonly header: SessionHeader;
|
|
14
|
+
/** The caller's own-session boundary fold (the `turnBoundary` projection). */
|
|
15
|
+
readonly boundary: TurnBoundaryProjection;
|
|
16
|
+
}
|
|
17
|
+
interface TitleView {
|
|
18
|
+
readonly text: string;
|
|
19
|
+
readonly unavailableCode?: string;
|
|
20
|
+
}
|
|
21
|
+
interface CompleteTitleMap extends ReadonlyMap<SessionIdValue, TitleView> {
|
|
22
|
+
get(id: SessionIdValue): TitleView;
|
|
23
|
+
}
|
|
24
|
+
interface AuthorizedDescendant {
|
|
25
|
+
readonly record: SessionRecord;
|
|
26
|
+
readonly descendants: Array<AuthorizedDescendant | null>;
|
|
27
|
+
}
|
|
28
|
+
interface DescendantVisit {
|
|
29
|
+
readonly node: AuthorizedDescendant | null;
|
|
30
|
+
readonly depth: number;
|
|
31
|
+
readonly next: DescendantVisit | undefined;
|
|
32
|
+
}
|
|
33
|
+
declare function callerOf(exec: ToolRunContext, ctx: Context): Caller;
|
|
34
|
+
declare function targetId(args: {
|
|
35
|
+
readonly session_id?: string;
|
|
36
|
+
}, caller: Caller): SessionIdValue;
|
|
37
|
+
declare function authorizeTarget(ctx: Context, caller: Caller, target: SessionIdValue, signal: AbortSignal): Promise<void>;
|
|
38
|
+
declare function recordAuthorized(record: SessionRecord, caller: Caller): boolean;
|
|
39
|
+
declare function assertObservedTargetAuthorized(caller: Caller, target: SessionIdValue, observed: SessionHeader): void;
|
|
40
|
+
declare function authorizeSessionIds(ctx: Context, caller: Caller, ids: readonly SessionIdValue[], signal: AbortSignal): Promise<ReadonlySet<SessionIdValue>>;
|
|
41
|
+
declare function readTitles(ctx: Context, caller: Caller, ids: readonly SessionIdValue[], signal: AbortSignal): Promise<CompleteTitleMap>;
|
|
42
|
+
declare function readTitle(ctx: Context, caller: Caller, id: SessionIdValue, signal: AbortSignal): Promise<TitleView>;
|
|
43
|
+
declare function authorizeDescendants(nodes: readonly SessionLineageNode[], caller: Caller): Array<AuthorizedDescendant | null>;
|
|
44
|
+
declare function visitDescendants(nodes: readonly (AuthorizedDescendant | null)[]): Generator<DescendantVisit>;
|
|
45
|
+
declare function descendantIds(nodes: readonly (AuthorizedDescendant | null)[]): SessionIdValue[];
|
|
46
|
+
declare function titleText(view: TitleView): string;
|
|
47
|
+
/** Workspace-scoped caller authorization, title access, and lineage projection. */
|
|
48
|
+
export declare const workspaceAccess: {
|
|
49
|
+
callerOf: typeof callerOf;
|
|
50
|
+
targetId: typeof targetId;
|
|
51
|
+
authorizeTarget: typeof authorizeTarget;
|
|
52
|
+
recordAuthorized: typeof recordAuthorized;
|
|
53
|
+
assertObservedTargetAuthorized: typeof assertObservedTargetAuthorized;
|
|
54
|
+
authorizeSessionIds: typeof authorizeSessionIds;
|
|
55
|
+
readTitles: typeof readTitles;
|
|
56
|
+
readTitle: typeof readTitle;
|
|
57
|
+
authorizeDescendants: typeof authorizeDescendants;
|
|
58
|
+
visitDescendants: typeof visitDescendants;
|
|
59
|
+
descendantIds: typeof descendantIds;
|
|
60
|
+
titleText: typeof titleText;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=workspace-access.d.ts.map
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-tool-session-query",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Workspace-authorized model-facing session history search, trace, and event read tools",
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./locale/*.json": "./locale/*.json",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"locale/*.json",
|
|
22
|
+
"lib/index.js",
|
|
23
|
+
"lib/types/**/*.d.ts",
|
|
24
|
+
"lib/types/**/*.d.ts.map",
|
|
25
|
+
"lib/**/*.js.map",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@unieai/cordis": "4.1.0",
|
|
32
|
+
"@unieai/rabi-agent": "0.2.2-rc.5",
|
|
33
|
+
"@unieai/rabi-llm": "0.2.2-rc.5",
|
|
34
|
+
"@unieai/rabi-session": "0.2.2-rc.5",
|
|
35
|
+
"@unieai/rabi-session-query": "0.2.2-rc.5",
|
|
36
|
+
"@unieai/rabi-system-prompt": "0.2.2-rc.5",
|
|
37
|
+
"@unieai/rabi-timeout": "0.2.2-rc.5",
|
|
38
|
+
"@unieai/rabi-tools": "0.2.2-rc.5"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@unieai/rabi-brand": "0.2.2-rc.5",
|
|
42
|
+
"@unieai/schemastery": "3.19.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing, workspace-authorized session-history search and read tools.
|
|
3
|
+
*
|
|
4
|
+
* @module @unieai/rabi-tool-session-query
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Context } from '@unieai/cordis'
|
|
8
|
+
import z from '@unieai/schemastery'
|
|
9
|
+
import { MAX_TIMER_DELAY_MS } from '@unieai/rabi-timeout'
|
|
10
|
+
import { defineTool } from '@unieai/rabi-tools'
|
|
11
|
+
import { toolInput } from './input.ts'
|
|
12
|
+
import { operations } from './operations.ts'
|
|
13
|
+
import { presentation } from './presentation.ts'
|
|
14
|
+
|
|
15
|
+
/** Cordis plugin name used by Loader diagnostics. */
|
|
16
|
+
export const name = 'tool-session-query'
|
|
17
|
+
|
|
18
|
+
/** Capability services required by the model-facing consumer. */
|
|
19
|
+
export const inject = ['tools', 'systemPrompt', 'sessionQuery', 'agents']
|
|
20
|
+
|
|
21
|
+
/** Default maximum number of authorized search hits returned by one call. */
|
|
22
|
+
export const DEFAULT_MAX_SEARCH_RESULTS = 100
|
|
23
|
+
|
|
24
|
+
/** Default cooperative deadline for either full-text search tool. */
|
|
25
|
+
export const DEFAULT_SEARCH_TIMEOUT_MS = 30_000
|
|
26
|
+
|
|
27
|
+
/** Deployment-owned search count and timeout bounds. */
|
|
28
|
+
export interface Config {
|
|
29
|
+
/** Maximum authorized hits returned by one search call. Defaults to 100. */
|
|
30
|
+
maxSearchResults?: number
|
|
31
|
+
/** Cooperative full-text search deadline in milliseconds. Defaults to 30000. */
|
|
32
|
+
searchTimeoutMs?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Schemastery config for Loader defaults and generated configuration docs. */
|
|
36
|
+
export const Config: z<Config> = z.object({
|
|
37
|
+
maxSearchResults: z.number().step(1).min(1).default(DEFAULT_MAX_SEARCH_RESULTS),
|
|
38
|
+
searchTimeoutMs: z.number().step(1).min(1).max(MAX_TIMER_DELAY_MS).default(DEFAULT_SEARCH_TIMEOUT_MS),
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
interface ResolvedConfig {
|
|
42
|
+
readonly maxSearchResults: number
|
|
43
|
+
readonly searchTimeoutMs: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const TEXT_OUTPUT = {
|
|
47
|
+
schema: { type: 'string' as const },
|
|
48
|
+
render: (_args: unknown, value: string) => [{ type: 'text' as const, text: value }],
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const PROMPT_TEXT =
|
|
52
|
+
'Use session_search to find relevant work from prior sessions, or session_event_search to search earlier '
|
|
53
|
+
+ 'events in one session. Search results are cursor-free and workspace-scoped. Follow a useful hit with '
|
|
54
|
+
+ 'session_trace, session_event_trace, or session_event_read when you need lineage, relationships, or exact data.'
|
|
55
|
+
|
|
56
|
+
/** Register all five tools and their shared model guidance. */
|
|
57
|
+
export function apply(ctx: Context, config: Config): void {
|
|
58
|
+
const resolved = resolveConfig(config)
|
|
59
|
+
ctx.systemPrompt.section({
|
|
60
|
+
name: 'tool:session-query',
|
|
61
|
+
order: ctx.systemPrompt.getSectionOrder('TOOL_SESSION_QUERY'),
|
|
62
|
+
text: PROMPT_TEXT,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
ctx.tools.register(defineTool({
|
|
66
|
+
name: 'session_search',
|
|
67
|
+
description: 'Search prior sessions in the caller workspace and return the strongest matching event from each session.',
|
|
68
|
+
parameters: toolInput.sessionSearchParameters,
|
|
69
|
+
output: TEXT_OUTPUT,
|
|
70
|
+
timeoutMs: resolved.searchTimeoutMs,
|
|
71
|
+
execute: (args, exec) => operations.executeSessionSearch(ctx, args, exec, resolved.maxSearchResults),
|
|
72
|
+
presentCall: presentation.presentSessionSearchCall,
|
|
73
|
+
}))
|
|
74
|
+
|
|
75
|
+
ctx.tools.register(defineTool({
|
|
76
|
+
name: 'session_event_search',
|
|
77
|
+
description: 'Search prior events in one authorized session; the current session excludes the step performing this call.',
|
|
78
|
+
parameters: toolInput.eventSearchParameters,
|
|
79
|
+
output: TEXT_OUTPUT,
|
|
80
|
+
timeoutMs: resolved.searchTimeoutMs,
|
|
81
|
+
execute: (args, exec) => operations.executeEventSearch(ctx, args, exec, resolved.maxSearchResults),
|
|
82
|
+
presentCall: presentation.presentEventSearchCall,
|
|
83
|
+
}))
|
|
84
|
+
|
|
85
|
+
ctx.tools.register(defineTool({
|
|
86
|
+
name: 'session_trace',
|
|
87
|
+
description: 'Read the authorized session lineage around one session, including complete visible ancestor and descendant relationships.',
|
|
88
|
+
parameters: toolInput.targetSessionParameter,
|
|
89
|
+
output: TEXT_OUTPUT,
|
|
90
|
+
isConcurrencySafe: () => true,
|
|
91
|
+
execute: (args, exec) => operations.executeSessionTrace(ctx, args, exec),
|
|
92
|
+
presentCall: presentation.presentSessionTraceCall,
|
|
93
|
+
}))
|
|
94
|
+
|
|
95
|
+
ctx.tools.register(defineTool({
|
|
96
|
+
name: 'session_event_trace',
|
|
97
|
+
description: 'Read every direct replacement and relationship to a cited source event for one event in an authorized session.',
|
|
98
|
+
parameters: {
|
|
99
|
+
...toolInput.targetSessionParameter,
|
|
100
|
+
seq: { type: 'integer', required: true, description: 'Target event sequence number.' },
|
|
101
|
+
},
|
|
102
|
+
output: TEXT_OUTPUT,
|
|
103
|
+
isConcurrencySafe: () => true,
|
|
104
|
+
execute: (args, exec) => operations.executeEventTrace(ctx, args, exec),
|
|
105
|
+
presentCall: args => presentation.presentEventTargetCall('Trace event', args),
|
|
106
|
+
}))
|
|
107
|
+
|
|
108
|
+
ctx.tools.register(defineTool({
|
|
109
|
+
name: 'session_event_read',
|
|
110
|
+
description: 'Read one full unabridged event and optional neighboring raw-event summaries from an authorized session.',
|
|
111
|
+
parameters: {
|
|
112
|
+
...toolInput.targetSessionParameter,
|
|
113
|
+
seq: { type: 'integer', required: true, description: 'Target event sequence number.' },
|
|
114
|
+
before: { type: 'integer', description: 'Number of preceding raw events to summarize. Omit for none.' },
|
|
115
|
+
after: { type: 'integer', description: 'Number of following raw events to summarize. Omit for none.' },
|
|
116
|
+
},
|
|
117
|
+
output: TEXT_OUTPUT,
|
|
118
|
+
isConcurrencySafe: () => true,
|
|
119
|
+
execute: (args, exec) => operations.executeEventRead(ctx, args, exec),
|
|
120
|
+
presentCall: args => presentation.presentEventTargetCall('Read event', args),
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function resolveConfig(config: Config): ResolvedConfig {
|
|
125
|
+
const maxSearchResults = config.maxSearchResults ?? DEFAULT_MAX_SEARCH_RESULTS
|
|
126
|
+
const searchTimeoutMs = config.searchTimeoutMs ?? DEFAULT_SEARCH_TIMEOUT_MS
|
|
127
|
+
if (!Number.isSafeInteger(maxSearchResults) || maxSearchResults < 1) {
|
|
128
|
+
throw new TypeError('tool-session-query: maxSearchResults must be a positive safe integer')
|
|
129
|
+
}
|
|
130
|
+
if (!Number.isInteger(searchTimeoutMs) || searchTimeoutMs < 1 || searchTimeoutMs > MAX_TIMER_DELAY_MS) {
|
|
131
|
+
throw new TypeError(
|
|
132
|
+
`tool-session-query: searchTimeoutMs must be a positive integer no greater than ${MAX_TIMER_DELAY_MS}`,
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
return { maxSearchResults, searchTimeoutMs }
|
|
136
|
+
}
|