opencode-mem-agents 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/contracts.d.ts +175 -0
- package/dist/contracts.js +170 -0
- package/dist/dashboard-html.d.ts +1 -1
- package/dist/dashboard-html.js +12 -12
- package/dist/index.js +273 -73
- package/dist/worker/config.d.ts +14 -0
- package/dist/worker/config.js +44 -0
- package/dist/worker/http.d.ts +23 -0
- package/dist/worker/http.js +130 -0
- package/dist/worker/repository.d.ts +61 -0
- package/dist/worker/repository.js +535 -0
- package/dist/worker/routes.d.ts +31 -0
- package/dist/worker/routes.js +251 -0
- package/dist/worker/server.d.ts +1 -0
- package/dist/worker/server.js +177 -0
- package/dist/worker/utils.d.ts +8 -0
- package/dist/worker/utils.js +98 -0
- package/dist/worker.d.ts +0 -16
- package/dist/worker.js +2 -647
- package/package.json +4 -2
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# opencode-mem-agents
|
|
2
|
+
|
|
3
|
+
Persistent local memory plugin for OpenCode with:
|
|
4
|
+
|
|
5
|
+
- SQLite + FTS5 storage
|
|
6
|
+
- Automatic tool-result capture
|
|
7
|
+
- Team-scoped memory tools
|
|
8
|
+
- Local dashboard UI
|
|
9
|
+
- Request/response trace journal for observability
|
|
10
|
+
|
|
11
|
+
## Runtime
|
|
12
|
+
|
|
13
|
+
- Node.js `>=18`
|
|
14
|
+
- Default worker: `http://127.0.0.1:37778`
|
|
15
|
+
- Default DB: `~/.opencode-mem/opencode-mem.db`
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install
|
|
21
|
+
npm run build
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm run build
|
|
28
|
+
npm test
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Worker API
|
|
32
|
+
|
|
33
|
+
- `GET /api/health`
|
|
34
|
+
- `GET /api/search`
|
|
35
|
+
- `GET /api/timeline` (`format=text|json`)
|
|
36
|
+
- `POST /api/observations/batch` (optional `project` filter enforced server-side)
|
|
37
|
+
- `POST /api/memory/save`
|
|
38
|
+
- `POST /api/session/tool-result`
|
|
39
|
+
- `GET /api/context/session`
|
|
40
|
+
- `GET /api/activity`
|
|
41
|
+
- `GET /api/traces`
|
|
42
|
+
|
|
43
|
+
All JSON responses include `traceId` for request correlation.
|
|
44
|
+
|
|
45
|
+
## Architecture
|
|
46
|
+
|
|
47
|
+
Worker internals are split for maintainability:
|
|
48
|
+
|
|
49
|
+
- `src/worker/server.ts` - HTTP lifecycle, auth/CORS, routing dispatch
|
|
50
|
+
- `src/worker/routes.ts` - request parsing + response shaping
|
|
51
|
+
- `src/worker/repository.ts` - SQLite schema + query/write logic
|
|
52
|
+
- `src/worker/http.ts` - transport helpers + boundary error handling
|
|
53
|
+
- `src/worker/config.ts` - runtime config loading
|
|
54
|
+
|
|
55
|
+
## Observability
|
|
56
|
+
|
|
57
|
+
`/api/traces` returns recent inbound/outbound/error events from the worker trace journal.
|
|
58
|
+
|
|
59
|
+
Trace payloads are:
|
|
60
|
+
|
|
61
|
+
- redacted for sensitive keys (`authorization`, `token`, `password`, `secret`, `apiKey`, `cookie`)
|
|
62
|
+
- redacted for common secret-like inline values in free text (`Bearer ...`, `sk-...`, `AKIA...`)
|
|
63
|
+
- size-capped before persistence
|
|
64
|
+
- pruned by age (`OPENCODE_MEM_TRACE_RETENTION_DAYS`, default `7`)
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
curl "http://127.0.0.1:37778/api/traces?limit=50"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Security Controls
|
|
73
|
+
|
|
74
|
+
- Optional API auth token:
|
|
75
|
+
- set `OPENCODE_MEM_API_TOKEN`
|
|
76
|
+
- send `Authorization: Bearer <token>` on `/api/*` (except health/readiness)
|
|
77
|
+
- Dashboard auth for protected endpoints:
|
|
78
|
+
- use the in-memory token button in the UI (`Set Token`)
|
|
79
|
+
- or open with `?token=...` or `#token=...` (token is stripped from URL on load)
|
|
80
|
+
- token is never persisted to localStorage/sessionStorage
|
|
81
|
+
- CORS defaults to localhost origins only
|
|
82
|
+
- Optional explicit CORS origin override:
|
|
83
|
+
- `OPENCODE_MEM_CORS_ORIGIN=https://your-origin.example`
|
|
84
|
+
- 500 responses are intentionally generic (`Internal server error`) to avoid leaking internals
|
|
85
|
+
|
|
86
|
+
## Reliability Controls
|
|
87
|
+
|
|
88
|
+
- Buffered observations are persisted to process-scoped disk queues (`pending-observations-<pid>.json`)
|
|
89
|
+
- Failed sends are retried from the persisted queue
|
|
90
|
+
- Flush retries are bounded and delivery concurrency is capped
|
|
91
|
+
- Tool-result writes are deduped using `(sessionId, callId, tool)` capture keys
|
|
92
|
+
- Timeline queries resolve around the true anchor at scale (not bounded to a fixed first-window scan)
|
|
93
|
+
- Context injection cache is scoped by `(sessionId, workflowId, agent, phase)` to prevent cross-session leakage
|
|
94
|
+
|
|
95
|
+
## Build Artifacts
|
|
96
|
+
|
|
97
|
+
The dashboard is built from `dashboard/` and embedded into `src/dashboard-html.ts` during `npm run build`.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const observationTypeSchema: z.ZodEnum<{
|
|
3
|
+
discovery: "discovery";
|
|
4
|
+
decision: "decision";
|
|
5
|
+
bugfix: "bugfix";
|
|
6
|
+
feature: "feature";
|
|
7
|
+
refactor: "refactor";
|
|
8
|
+
change: "change";
|
|
9
|
+
contract: "contract";
|
|
10
|
+
blocker: "blocker";
|
|
11
|
+
"test-result": "test-result";
|
|
12
|
+
"review-finding": "review-finding";
|
|
13
|
+
}>;
|
|
14
|
+
export declare const signalSchema: z.ZodEnum<{
|
|
15
|
+
high: "high";
|
|
16
|
+
medium: "medium";
|
|
17
|
+
low: "low";
|
|
18
|
+
}>;
|
|
19
|
+
export declare const roleSchema: z.ZodEnum<{
|
|
20
|
+
default: "default";
|
|
21
|
+
lead: "lead";
|
|
22
|
+
backend: "backend";
|
|
23
|
+
frontend: "frontend";
|
|
24
|
+
database: "database";
|
|
25
|
+
test: "test";
|
|
26
|
+
security: "security";
|
|
27
|
+
reviewer: "reviewer";
|
|
28
|
+
}>;
|
|
29
|
+
export declare const searchOrderSchema: z.ZodEnum<{
|
|
30
|
+
created_desc: "created_desc";
|
|
31
|
+
created_asc: "created_asc";
|
|
32
|
+
id_desc: "id_desc";
|
|
33
|
+
id_asc: "id_asc";
|
|
34
|
+
}>;
|
|
35
|
+
export declare const searchParamsSchema: z.ZodObject<{
|
|
36
|
+
query: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
37
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
38
|
+
type: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
39
|
+
discovery: "discovery";
|
|
40
|
+
decision: "decision";
|
|
41
|
+
bugfix: "bugfix";
|
|
42
|
+
feature: "feature";
|
|
43
|
+
refactor: "refactor";
|
|
44
|
+
change: "change";
|
|
45
|
+
contract: "contract";
|
|
46
|
+
blocker: "blocker";
|
|
47
|
+
"test-result": "test-result";
|
|
48
|
+
"review-finding": "review-finding";
|
|
49
|
+
}>>>;
|
|
50
|
+
signal: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
51
|
+
high: "high";
|
|
52
|
+
medium: "medium";
|
|
53
|
+
low: "low";
|
|
54
|
+
}>>>;
|
|
55
|
+
agent: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
56
|
+
dateStart: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
57
|
+
dateEnd: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
58
|
+
since_id: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
59
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
60
|
+
offset: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
61
|
+
orderBy: z.ZodDefault<z.ZodEnum<{
|
|
62
|
+
created_desc: "created_desc";
|
|
63
|
+
created_asc: "created_asc";
|
|
64
|
+
id_desc: "id_desc";
|
|
65
|
+
id_asc: "id_asc";
|
|
66
|
+
}>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
export declare const timelineParamsSchema: z.ZodObject<{
|
|
69
|
+
anchor: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
70
|
+
query: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
71
|
+
depth_before: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
72
|
+
depth_after: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
73
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
74
|
+
format: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodEnum<{
|
|
75
|
+
text: "text";
|
|
76
|
+
json: "json";
|
|
77
|
+
}>>>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
export declare const observationsBatchBodySchema: z.ZodObject<{
|
|
80
|
+
ids: z.ZodArray<z.ZodCoercedNumber<unknown>>;
|
|
81
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
export declare const memorySaveBodySchema: z.ZodObject<{
|
|
84
|
+
sessionId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
85
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
86
|
+
type: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
discovery: "discovery";
|
|
88
|
+
decision: "decision";
|
|
89
|
+
bugfix: "bugfix";
|
|
90
|
+
feature: "feature";
|
|
91
|
+
refactor: "refactor";
|
|
92
|
+
change: "change";
|
|
93
|
+
contract: "contract";
|
|
94
|
+
blocker: "blocker";
|
|
95
|
+
"test-result": "test-result";
|
|
96
|
+
"review-finding": "review-finding";
|
|
97
|
+
}>>>;
|
|
98
|
+
title: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
99
|
+
text: z.ZodString;
|
|
100
|
+
facts: z.ZodDefault<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
|
|
101
|
+
narrative: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
102
|
+
concepts: z.ZodDefault<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
|
|
103
|
+
files_read: z.ZodDefault<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
|
|
104
|
+
files_modified: z.ZodDefault<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
|
|
105
|
+
agent: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
106
|
+
workflow_id: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
107
|
+
task_id: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
108
|
+
phase: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
109
|
+
signal: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
110
|
+
high: "high";
|
|
111
|
+
medium: "medium";
|
|
112
|
+
low: "low";
|
|
113
|
+
}>>>;
|
|
114
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
115
|
+
signal: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
116
|
+
high: "high";
|
|
117
|
+
medium: "medium";
|
|
118
|
+
low: "low";
|
|
119
|
+
}>>>;
|
|
120
|
+
agent: z.ZodOptional<z.ZodObject<{
|
|
121
|
+
agentName: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
122
|
+
workflowId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
123
|
+
taskId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
124
|
+
phase: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
export declare const toolResultBodySchema: z.ZodObject<{
|
|
129
|
+
sessionId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
130
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
131
|
+
tool: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
132
|
+
callId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
133
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
134
|
+
output: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
135
|
+
title: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
136
|
+
files_modified: z.ZodDefault<z.ZodType<string[], unknown, z.core.$ZodTypeInternals<string[], unknown>>>;
|
|
137
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
138
|
+
signal: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodEnum<{
|
|
139
|
+
high: "high";
|
|
140
|
+
medium: "medium";
|
|
141
|
+
low: "low";
|
|
142
|
+
}>>>;
|
|
143
|
+
agent: z.ZodOptional<z.ZodObject<{
|
|
144
|
+
agentName: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
145
|
+
workflowId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
146
|
+
taskId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
147
|
+
phase: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
148
|
+
}, z.core.$strip>>;
|
|
149
|
+
timestamp: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
150
|
+
}, z.core.$strip>>;
|
|
151
|
+
}, z.core.$strip>;
|
|
152
|
+
export declare const contextSessionParamsSchema: z.ZodObject<{
|
|
153
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
154
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
155
|
+
agent: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
156
|
+
sessionId: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
157
|
+
}, z.core.$strip>;
|
|
158
|
+
export declare const activityParamsSchema: z.ZodObject<{
|
|
159
|
+
project: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
160
|
+
since_id: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
161
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
162
|
+
role: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
export declare const tracesParamsSchema: z.ZodObject<{
|
|
165
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
166
|
+
trace_id: z.ZodType<string | undefined, unknown, z.core.$ZodTypeInternals<string | undefined, unknown>>;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
export type SearchParams = z.infer<typeof searchParamsSchema>;
|
|
169
|
+
export type TimelineParams = z.infer<typeof timelineParamsSchema>;
|
|
170
|
+
export type ObservationsBatchBody = z.infer<typeof observationsBatchBodySchema>;
|
|
171
|
+
export type MemorySaveBody = z.infer<typeof memorySaveBodySchema>;
|
|
172
|
+
export type ToolResultBody = z.infer<typeof toolResultBodySchema>;
|
|
173
|
+
export type ContextSessionParams = z.infer<typeof contextSessionParamsSchema>;
|
|
174
|
+
export type ActivityParams = z.infer<typeof activityParamsSchema>;
|
|
175
|
+
export type TracesParams = z.infer<typeof tracesParamsSchema>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function optionalString(max) {
|
|
3
|
+
return z.preprocess((value) => {
|
|
4
|
+
if (typeof value !== "string")
|
|
5
|
+
return value;
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
return trimmed === "" ? undefined : trimmed;
|
|
8
|
+
}, z.string().max(max).optional());
|
|
9
|
+
}
|
|
10
|
+
function optionalIsoDate() {
|
|
11
|
+
return optionalString(100).refine((value) => {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return true;
|
|
14
|
+
return Number.isFinite(Date.parse(value));
|
|
15
|
+
}, "must be a valid ISO date string");
|
|
16
|
+
}
|
|
17
|
+
function optionalStringArray(maxItems, maxLength) {
|
|
18
|
+
return z.preprocess((value) => {
|
|
19
|
+
if (Array.isArray(value))
|
|
20
|
+
return value;
|
|
21
|
+
if (typeof value !== "string")
|
|
22
|
+
return [];
|
|
23
|
+
const trimmed = value.trim();
|
|
24
|
+
if (!trimmed)
|
|
25
|
+
return [];
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(trimmed);
|
|
28
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [trimmed];
|
|
32
|
+
}
|
|
33
|
+
}, z.array(z.string().trim().min(1).max(maxLength)).max(maxItems));
|
|
34
|
+
}
|
|
35
|
+
const observationTypeValues = [
|
|
36
|
+
"discovery",
|
|
37
|
+
"decision",
|
|
38
|
+
"bugfix",
|
|
39
|
+
"feature",
|
|
40
|
+
"refactor",
|
|
41
|
+
"change",
|
|
42
|
+
"contract",
|
|
43
|
+
"blocker",
|
|
44
|
+
"test-result",
|
|
45
|
+
"review-finding",
|
|
46
|
+
];
|
|
47
|
+
const signalValues = ["high", "medium", "low"];
|
|
48
|
+
const roleValues = [
|
|
49
|
+
"lead",
|
|
50
|
+
"backend",
|
|
51
|
+
"frontend",
|
|
52
|
+
"database",
|
|
53
|
+
"test",
|
|
54
|
+
"security",
|
|
55
|
+
"reviewer",
|
|
56
|
+
"default",
|
|
57
|
+
];
|
|
58
|
+
export const observationTypeSchema = z.enum(observationTypeValues);
|
|
59
|
+
export const signalSchema = z.enum(signalValues);
|
|
60
|
+
export const roleSchema = z.enum(roleValues);
|
|
61
|
+
export const searchOrderSchema = z.enum([
|
|
62
|
+
"created_desc",
|
|
63
|
+
"created_asc",
|
|
64
|
+
"id_desc",
|
|
65
|
+
"id_asc",
|
|
66
|
+
]);
|
|
67
|
+
export const searchParamsSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
query: optionalString(512),
|
|
70
|
+
project: optionalString(512),
|
|
71
|
+
type: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), observationTypeSchema.optional()),
|
|
72
|
+
signal: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), signalSchema.optional()),
|
|
73
|
+
agent: optionalString(128),
|
|
74
|
+
dateStart: optionalIsoDate(),
|
|
75
|
+
dateEnd: optionalIsoDate(),
|
|
76
|
+
since_id: z.coerce.number().int().min(0).max(10_000_000).default(0),
|
|
77
|
+
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
78
|
+
offset: z.coerce.number().int().min(0).max(100_000).default(0),
|
|
79
|
+
orderBy: searchOrderSchema.default("created_desc"),
|
|
80
|
+
})
|
|
81
|
+
.refine((value) => {
|
|
82
|
+
if (!value.dateStart || !value.dateEnd)
|
|
83
|
+
return true;
|
|
84
|
+
return Date.parse(value.dateStart) <= Date.parse(value.dateEnd);
|
|
85
|
+
}, {
|
|
86
|
+
message: "dateStart must be earlier than or equal to dateEnd",
|
|
87
|
+
path: ["dateStart"],
|
|
88
|
+
});
|
|
89
|
+
export const timelineParamsSchema = z.object({
|
|
90
|
+
anchor: z.preprocess((value) => (value === "" ? undefined : value), z.coerce.number().int().positive().optional()),
|
|
91
|
+
query: optionalString(512),
|
|
92
|
+
depth_before: z.coerce.number().int().min(0).max(100).default(10),
|
|
93
|
+
depth_after: z.coerce.number().int().min(0).max(100).default(10),
|
|
94
|
+
project: optionalString(512),
|
|
95
|
+
format: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? "text" : value), z.enum(["text", "json"]).default("text")),
|
|
96
|
+
});
|
|
97
|
+
export const observationsBatchBodySchema = z.object({
|
|
98
|
+
ids: z.array(z.coerce.number().int().positive()).min(1).max(200),
|
|
99
|
+
project: optionalString(512),
|
|
100
|
+
});
|
|
101
|
+
export const memorySaveBodySchema = z.object({
|
|
102
|
+
sessionId: optionalString(256),
|
|
103
|
+
project: optionalString(512),
|
|
104
|
+
type: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), observationTypeSchema.optional()),
|
|
105
|
+
title: optionalString(500),
|
|
106
|
+
text: z.string().trim().min(1).max(8192),
|
|
107
|
+
facts: optionalStringArray(200, 1024).default([]),
|
|
108
|
+
narrative: optionalString(4096),
|
|
109
|
+
concepts: optionalStringArray(200, 256).default([]),
|
|
110
|
+
files_read: optionalStringArray(500, 4096).default([]),
|
|
111
|
+
files_modified: optionalStringArray(500, 4096).default([]),
|
|
112
|
+
agent: optionalString(128),
|
|
113
|
+
workflow_id: optionalString(512),
|
|
114
|
+
task_id: optionalString(512),
|
|
115
|
+
phase: optionalString(256),
|
|
116
|
+
signal: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), signalSchema.optional()),
|
|
117
|
+
metadata: z
|
|
118
|
+
.object({
|
|
119
|
+
signal: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), signalSchema.optional()),
|
|
120
|
+
agent: z
|
|
121
|
+
.object({
|
|
122
|
+
agentName: optionalString(128),
|
|
123
|
+
workflowId: optionalString(512),
|
|
124
|
+
taskId: optionalString(512),
|
|
125
|
+
phase: optionalString(256),
|
|
126
|
+
})
|
|
127
|
+
.optional(),
|
|
128
|
+
})
|
|
129
|
+
.optional(),
|
|
130
|
+
});
|
|
131
|
+
export const toolResultBodySchema = z.object({
|
|
132
|
+
sessionId: optionalString(256),
|
|
133
|
+
project: optionalString(512),
|
|
134
|
+
tool: optionalString(100),
|
|
135
|
+
callId: optionalString(256),
|
|
136
|
+
args: z.unknown().optional(),
|
|
137
|
+
output: optionalString(8192),
|
|
138
|
+
title: optionalString(500),
|
|
139
|
+
files_modified: optionalStringArray(500, 4096).default([]),
|
|
140
|
+
metadata: z
|
|
141
|
+
.object({
|
|
142
|
+
signal: z.preprocess((value) => (typeof value === "string" && value.trim() === "" ? undefined : value), signalSchema.optional()),
|
|
143
|
+
agent: z
|
|
144
|
+
.object({
|
|
145
|
+
agentName: optionalString(128),
|
|
146
|
+
workflowId: optionalString(512),
|
|
147
|
+
taskId: optionalString(512),
|
|
148
|
+
phase: optionalString(256),
|
|
149
|
+
})
|
|
150
|
+
.optional(),
|
|
151
|
+
timestamp: z.coerce.number().int().positive().optional(),
|
|
152
|
+
})
|
|
153
|
+
.optional(),
|
|
154
|
+
});
|
|
155
|
+
export const contextSessionParamsSchema = z.object({
|
|
156
|
+
project: optionalString(512),
|
|
157
|
+
limit: z.coerce.number().int().min(1).max(100).default(10),
|
|
158
|
+
agent: optionalString(128),
|
|
159
|
+
sessionId: optionalString(256),
|
|
160
|
+
});
|
|
161
|
+
export const activityParamsSchema = z.object({
|
|
162
|
+
project: optionalString(512),
|
|
163
|
+
since_id: z.coerce.number().int().min(0).max(10_000_000).default(0),
|
|
164
|
+
limit: z.coerce.number().int().min(1).max(500).default(100),
|
|
165
|
+
role: optionalString(64),
|
|
166
|
+
});
|
|
167
|
+
export const tracesParamsSchema = z.object({
|
|
168
|
+
limit: z.coerce.number().int().min(1).max(500).default(100),
|
|
169
|
+
trace_id: optionalString(64),
|
|
170
|
+
});
|