@lota-sdk/shared 0.3.3 → 0.4.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/schemas/tools.ts +101 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lota-sdk/shared",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod'
2
2
 
3
- import { AgentPlanDraftSchema } from './agent-plan-draft'
3
+ import { AgentPlanDraftSchema, AgentPlanEdgeDraftSchema } from './agent-plan-draft'
4
4
  import { baseChatMessageSchema } from './chat-api'
5
5
  import type { AnyChatMessage } from './chat-message'
6
6
  import {
@@ -87,34 +87,123 @@ const targetThreadIdSchema = z
87
87
  const runIdSchema = z.string().trim().min(1)
88
88
  const replaceReasonSchema = z.string().trim().min(1).max(1000)
89
89
 
90
- const ExecutionPlanCreateArgsSchema = AgentPlanDraftSchema.extend({
90
+ export const ExecutionPlanCreateArgsSchema = AgentPlanDraftSchema.extend({
91
91
  action: z.literal('create'),
92
92
  targetThreadId: targetThreadIdSchema.optional(),
93
93
  }).strict()
94
94
 
95
- const ExecutionPlanCreateProjectArgsSchema = AgentPlanDraftSchema.extend({
95
+ export const ExecutionPlanCreateProjectArgsSchema = AgentPlanDraftSchema.extend({
96
96
  action: z.literal('create-project'),
97
97
  projectTitle: projectTitleSchema.optional(),
98
98
  targetThreadId: targetThreadIdSchema.optional(),
99
99
  }).strict()
100
100
 
101
- const ExecutionPlanReplaceArgsSchema = AgentPlanDraftSchema.extend({
101
+ export const ExecutionPlanReplaceArgsSchema = AgentPlanDraftSchema.extend({
102
102
  action: z.literal('replace'),
103
103
  runId: runIdSchema.describe('Required for replace and resume.'),
104
104
  reason: replaceReasonSchema.describe('Required for replace.'),
105
105
  }).strict()
106
106
 
107
- const ExecutionPlanResumeArgsSchema = z
107
+ export const ExecutionPlanResumeArgsSchema = z
108
108
  .object({ action: z.literal('resume'), runId: runIdSchema.describe('Required for replace and resume.') })
109
109
  .strict()
110
110
 
111
- export const ExecutionPlanArgsSchema = z.discriminatedUnion('action', [
112
- ExecutionPlanCreateArgsSchema,
113
- ExecutionPlanCreateProjectArgsSchema,
114
- ExecutionPlanReplaceArgsSchema,
115
- ExecutionPlanResumeArgsSchema,
116
- ])
117
- export type ExecutionPlanArgs = z.infer<typeof ExecutionPlanArgsSchema>
111
+ const ExecutionPlanBaseArgsSchema = z
112
+ .object({
113
+ action: ExecutionPlanActionSchema,
114
+ title: AgentPlanDraftSchema.shape.title.optional(),
115
+ objective: AgentPlanDraftSchema.shape.objective.optional(),
116
+ nodes: AgentPlanDraftSchema.shape.nodes.optional(),
117
+ edges: z.array(AgentPlanEdgeDraftSchema).optional(),
118
+ projectTitle: projectTitleSchema.optional(),
119
+ targetThreadId: targetThreadIdSchema.optional(),
120
+ runId: runIdSchema.describe('Required for replace and resume.').optional(),
121
+ reason: replaceReasonSchema.describe('Required for replace.').optional(),
122
+ })
123
+ .strict()
124
+
125
+ function addMissingExecutionPlanFieldIssue(ctx: z.RefinementCtx, path: string, message: string) {
126
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [path], message })
127
+ }
128
+
129
+ function addUnexpectedExecutionPlanFieldIssue(ctx: z.RefinementCtx, path: string, message: string) {
130
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [path], message })
131
+ }
132
+
133
+ export const ExecutionPlanArgsSchema = ExecutionPlanBaseArgsSchema.superRefine((value, ctx) => {
134
+ const requiresDraft = value.action === 'create' || value.action === 'create-project' || value.action === 'replace'
135
+
136
+ if (requiresDraft) {
137
+ if (value.title === undefined) {
138
+ addMissingExecutionPlanFieldIssue(ctx, 'title', 'title is required for create, create-project, and replace.')
139
+ }
140
+ if (value.objective === undefined) {
141
+ addMissingExecutionPlanFieldIssue(
142
+ ctx,
143
+ 'objective',
144
+ 'objective is required for create, create-project, and replace.',
145
+ )
146
+ }
147
+ if (value.nodes === undefined) {
148
+ addMissingExecutionPlanFieldIssue(ctx, 'nodes', 'nodes is required for create, create-project, and replace.')
149
+ }
150
+ }
151
+
152
+ if (value.action === 'replace') {
153
+ if (value.runId === undefined) {
154
+ addMissingExecutionPlanFieldIssue(ctx, 'runId', 'runId is required for replace.')
155
+ }
156
+ if (value.reason === undefined) {
157
+ addMissingExecutionPlanFieldIssue(ctx, 'reason', 'reason is required for replace.')
158
+ }
159
+ }
160
+
161
+ if (value.action === 'resume') {
162
+ if (value.runId === undefined) {
163
+ addMissingExecutionPlanFieldIssue(ctx, 'runId', 'runId is required for resume.')
164
+ }
165
+
166
+ for (const path of ['title', 'objective', 'nodes', 'edges', 'projectTitle', 'targetThreadId', 'reason'] as const) {
167
+ if (value[path] !== undefined) {
168
+ addUnexpectedExecutionPlanFieldIssue(
169
+ ctx,
170
+ path,
171
+ `${path} is not allowed when action is "resume". Use only action and runId.`,
172
+ )
173
+ }
174
+ }
175
+ }
176
+
177
+ if (value.action === 'create') {
178
+ for (const path of ['projectTitle', 'runId', 'reason'] as const) {
179
+ if (value[path] !== undefined) {
180
+ addUnexpectedExecutionPlanFieldIssue(ctx, path, `${path} is not allowed when action is "create".`)
181
+ }
182
+ }
183
+ }
184
+
185
+ if (value.action === 'create-project') {
186
+ for (const path of ['runId', 'reason'] as const) {
187
+ if (value[path] !== undefined) {
188
+ addUnexpectedExecutionPlanFieldIssue(ctx, path, `${path} is not allowed when action is "create-project".`)
189
+ }
190
+ }
191
+ }
192
+
193
+ if (value.action === 'replace') {
194
+ for (const path of ['projectTitle', 'targetThreadId'] as const) {
195
+ if (value[path] !== undefined) {
196
+ addUnexpectedExecutionPlanFieldIssue(ctx, path, `${path} is not allowed when action is "replace".`)
197
+ }
198
+ }
199
+ }
200
+ })
201
+
202
+ export type ExecutionPlanArgs =
203
+ | z.infer<typeof ExecutionPlanCreateArgsSchema>
204
+ | z.infer<typeof ExecutionPlanCreateProjectArgsSchema>
205
+ | z.infer<typeof ExecutionPlanReplaceArgsSchema>
206
+ | z.infer<typeof ExecutionPlanResumeArgsSchema>
118
207
 
119
208
  export const ExecutionPlanQueryArgsSchema = z
120
209
  .object({