@lota-sdk/shared 0.4.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lota-sdk/shared",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -1,7 +1,7 @@
1
1
  export const OPENAI_REASONING_MODEL_ID = 'openai/gpt-5.4' as const
2
2
 
3
3
  export const OPENROUTER_GEMINI_FLASH_MODEL_ID = 'openrouter/google/gemini-3-flash-preview' as const
4
- export const OPENROUTER_TEAM_AGENT_MODEL_ID = 'openrouter/google/gemini-3.1-pro-preview' as const
4
+ export const OPENROUTER_TEAM_AGENT_MODEL_ID = 'openrouter/google/gemini-3-flash-preview' as const
5
5
  export const OPENROUTER_WEB_RESEARCH_MODEL_ID = 'openrouter/stepfun/step-3.5-flash' as const
6
6
  export const OPENROUTER_FAST_REASONING_MODEL_ID = 'openrouter/qwen/qwen3.5-flash-02-23' as const
7
7
  export const OPENROUTER_STRUCTURED_REASONING_MODEL_ID = 'openrouter/google/gemini-3.1-pro-preview' as const
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from './runtime/agent-types'
5
5
  export * from './runtime/chat-message-metadata'
6
6
  export * from './runtime/execution-plan-result'
7
7
  export * from './schemas/agent-plan-draft'
8
+ export * from './schemas/artifact'
8
9
  export * from './schemas/chat-api'
9
10
  export * from './schemas/chat-message'
10
11
  export * from './schemas/common'
@@ -3,6 +3,7 @@ import type {
3
3
  Output,
4
4
  PrepareStepFunction,
5
5
  StopCondition,
6
+ ToolCallRepairFunction,
6
7
  ToolLoopAgentOnFinishCallback,
7
8
  ToolSet,
8
9
  } from 'ai'
@@ -16,6 +17,7 @@ export interface CreateRoutedAgentOptions<TTools extends ToolSet = ToolSet> {
16
17
  headers?: Record<string, string>
17
18
  stopWhen?: StopCondition<TTools> | Array<StopCondition<TTools>>
18
19
  prepareStep?: PrepareStepFunction<TTools>
20
+ repairToolCall?: ToolCallRepairFunction<TTools>
19
21
  maxRetries?: number
20
22
  output?: Output.Output
21
23
  modelOverride?: { model: LanguageModel; providerOptions?: Record<string, unknown> }
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod'
2
+
3
+ import { recordIdSchema } from './common'
4
+
5
+ const dbDateTimeSchema = z.coerce.date()
6
+ const apiDateTimeSchema = z.string().datetime({ offset: true })
7
+
8
+ export const ArtifactKindSchema = z
9
+ .enum(['document', 'plan', 'brief', 'report', 'analysis', 'spec'])
10
+ .meta({ id: 'ArtifactKindSchema' })
11
+ export type ArtifactKind = z.infer<typeof ArtifactKindSchema>
12
+
13
+ export const ArtifactStatusSchema = z.enum(['active', 'superseded', 'archived']).meta({ id: 'ArtifactStatusSchema' })
14
+ export type ArtifactStatus = z.infer<typeof ArtifactStatusSchema>
15
+
16
+ export const ArtifactReferenceTargetSchema = z
17
+ .enum(['artifact', 'document'])
18
+ .meta({ id: 'ArtifactReferenceTargetSchema' })
19
+ export type ArtifactReferenceTarget = z.infer<typeof ArtifactReferenceTargetSchema>
20
+
21
+ export const ArtifactReferenceSchema = z
22
+ .object({
23
+ uri: z.string().trim().min(1).max(1000),
24
+ targetType: ArtifactReferenceTargetSchema,
25
+ targetId: z.string().trim().min(1).max(255),
26
+ })
27
+ .strict()
28
+ .meta({ id: 'ArtifactReferenceSchema' })
29
+ export type ArtifactReference = z.infer<typeof ArtifactReferenceSchema>
30
+
31
+ export const ArtifactRecordSchema = z
32
+ .object({
33
+ id: recordIdSchema,
34
+ organizationId: recordIdSchema,
35
+ authorAgentId: z.string(),
36
+ title: z.string(),
37
+ artifactKind: ArtifactKindSchema,
38
+ templateId: z.string(),
39
+ canonicalKey: z.string(),
40
+ version: z.number().int().positive(),
41
+ status: ArtifactStatusSchema,
42
+ supersededBy: recordIdSchema.optional(),
43
+ storageKey: z.string(),
44
+ description: z.string().optional(),
45
+ tags: z.array(z.string()).default([]),
46
+ references: z.array(ArtifactReferenceSchema).default([]),
47
+ sourceThreadId: recordIdSchema.optional(),
48
+ sourcePlanRunId: recordIdSchema.optional(),
49
+ sourcePlanNodeId: z.string().optional(),
50
+ createdAt: dbDateTimeSchema,
51
+ updatedAt: dbDateTimeSchema.optional(),
52
+ })
53
+ .meta({ id: 'ArtifactRecordSchema' })
54
+ export type ArtifactRecord = z.infer<typeof ArtifactRecordSchema>
55
+
56
+ export const ArtifactVersionSummarySchema = z
57
+ .object({
58
+ id: z.string(),
59
+ title: z.string(),
60
+ version: z.number().int().positive(),
61
+ status: ArtifactStatusSchema,
62
+ createdAt: apiDateTimeSchema,
63
+ })
64
+ .strict()
65
+ .meta({ id: 'ArtifactVersionSummarySchema' })
66
+ export type ArtifactVersionSummary = z.infer<typeof ArtifactVersionSummarySchema>
67
+
68
+ export const PublishArtifactArgsSchema = z
69
+ .object({
70
+ organizationId: z.string().trim().min(1).max(255),
71
+ authorAgentId: z.string().trim().min(1).max(255),
72
+ title: z.string().trim().min(1).max(300),
73
+ artifactKind: ArtifactKindSchema,
74
+ templateId: z.string().trim().min(1).max(255),
75
+ content: z
76
+ .string()
77
+ .min(1)
78
+ .refine((value) => value.trim().length > 0, 'Content is required.'),
79
+ canonicalKey: z.string().trim().min(1).max(255).optional(),
80
+ description: z.string().trim().min(1).max(1000).optional(),
81
+ tags: z.array(z.string().trim().min(1).max(100)).optional().default([]),
82
+ sourceThreadId: z.string().trim().min(1).max(255).optional(),
83
+ sourcePlanRunId: z.string().trim().min(1).max(255).optional(),
84
+ sourcePlanNodeId: z.string().trim().min(1).max(255).optional(),
85
+ deliverableName: z.string().trim().min(1).max(200).optional(),
86
+ })
87
+ .strict()
88
+ .meta({ id: 'PublishArtifactArgsSchema' })
89
+ export type PublishArtifactArgs = z.infer<typeof PublishArtifactArgsSchema>
90
+
91
+ export const GetArtifactResultSchema = z
92
+ .object({
93
+ artifact: ArtifactRecordSchema,
94
+ content: z.string(),
95
+ versions: z.array(ArtifactVersionSummarySchema),
96
+ backlinks: z.array(ArtifactRecordSchema),
97
+ })
98
+ .meta({ id: 'GetArtifactResultSchema' })
99
+ export type GetArtifactResult = z.infer<typeof GetArtifactResultSchema>
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod'
2
2
 
3
+ import { ArtifactKindSchema } from './artifact'
3
4
  import { recordIdSchema } from './common'
4
5
 
5
6
  /** For DB record schemas — accepts Date objects from SurrealDB and coerces strings */
@@ -220,6 +221,14 @@ export const PlanArtifactSpecSchema = z
220
221
  required: z.boolean().default(true),
221
222
  schemaRef: z.string().trim().min(1).max(200).optional(),
222
223
  description: z.string().trim().min(1).max(1000),
224
+ publishAs: z
225
+ .object({
226
+ artifactKind: ArtifactKindSchema,
227
+ templateId: z.string().trim().min(1).max(255),
228
+ canonicalKey: z.string().trim().min(1).max(255).optional(),
229
+ })
230
+ .strict()
231
+ .optional(),
223
232
  })
224
233
  .strict()
225
234
  export type PlanArtifactSpec = z.infer<typeof PlanArtifactSpecSchema>
@@ -419,7 +428,13 @@ export const PlanArtifactSubmissionSchema = z
419
428
  name: z.string().trim().min(1).max(200),
420
429
  kind: PlanArtifactKindSchema,
421
430
  description: z.string().trim().max(1000).optional(),
431
+ content: z
432
+ .string()
433
+ .min(1)
434
+ .refine((value) => value.trim().length > 0, 'Content is required.')
435
+ .optional(),
422
436
  payload: planStructuredPayloadSchema.optional(),
437
+ publishedArtifactId: z.string().trim().min(1).max(255).optional(),
423
438
  })
424
439
  .strict()
425
440
  export type PlanArtifactSubmission = z.infer<typeof PlanArtifactSubmissionSchema>
@@ -471,7 +486,7 @@ export const PlanDependencyTriggerModeSchema = z.enum(['block', 'notify', 'best-
471
486
  export type PlanDependencyTriggerMode = z.infer<typeof PlanDependencyTriggerModeSchema>
472
487
 
473
488
  export const PlanDependencySchema = z.object({
474
- sourcePlanTitle: z.string().trim().min(1).max(200),
489
+ sourcePlanSpecId: z.string().trim().min(1).max(255),
475
490
  sourceNodeId: z.string().trim().min(1).max(200),
476
491
  artifactName: z.string().trim().min(1).max(200),
477
492
  triggerMode: PlanDependencyTriggerModeSchema.default('block'),
@@ -685,7 +700,9 @@ export const PlanArtifactSchema = z.object({
685
700
  pointer: z.string(),
686
701
  schemaRef: z.string().optional(),
687
702
  description: z.string().optional(),
703
+ content: z.string().optional(),
688
704
  payload: planStructuredPayloadSchema.optional(),
705
+ publishedArtifactId: recordIdSchema.optional(),
689
706
  createdAt: dbDateTimeSchema,
690
707
  })
691
708
  export type PlanArtifactRecord = z.infer<typeof PlanArtifactSchema>
@@ -796,7 +813,9 @@ export const SerializablePlanArtifactSchema = z.object({
796
813
  pointer: z.string(),
797
814
  schemaRef: z.string().nullish(),
798
815
  description: z.string().nullish(),
816
+ content: z.string().nullish(),
799
817
  payload: planStructuredPayloadSchema.nullish(),
818
+ publishedArtifactId: z.string().nullish(),
800
819
  createdAt: z.iso.datetime(),
801
820
  })
802
821
  export type SerializablePlanArtifact = z.infer<typeof SerializablePlanArtifactSchema>
@@ -908,18 +927,28 @@ export const SerializableExecutionPlanSchema = z.object({
908
927
  })
909
928
  export type SerializableExecutionPlan = z.infer<typeof SerializableExecutionPlanSchema>
910
929
 
911
- export const PlanTemplateRecordSchema = z.object({
912
- id: recordIdSchema,
913
- organizationId: recordIdSchema,
914
- name: z.string(),
915
- description: z.string().optional(),
916
- draft: PlanDraftSchema,
917
- tags: z.array(z.string()).default([]),
918
- source: PlanTemplateSourceSchema,
919
- sourceRef: z.string().optional(),
920
- createdAt: dbDateTimeSchema,
921
- updatedAt: dbDateTimeSchema.optional(),
922
- })
930
+ export const PlanTemplateRecordSchema = z
931
+ .object({
932
+ id: recordIdSchema,
933
+ organizationId: recordIdSchema,
934
+ name: z.string(),
935
+ description: z.string().optional(),
936
+ draft: PlanDraftSchema,
937
+ tags: z.array(z.string()).default([]),
938
+ source: PlanTemplateSourceSchema,
939
+ sourceRef: z.string().optional(),
940
+ createdAt: dbDateTimeSchema,
941
+ updatedAt: dbDateTimeSchema.optional(),
942
+ })
943
+ .superRefine((value, ctx) => {
944
+ if (value.source !== 'user' && (!value.sourceRef || value.sourceRef.trim().length === 0)) {
945
+ ctx.addIssue({
946
+ code: z.ZodIssueCode.custom,
947
+ path: ['sourceRef'],
948
+ message: `sourceRef is required when source is "${value.source}".`,
949
+ })
950
+ }
951
+ })
923
952
  export type PlanTemplateRecord = z.infer<typeof PlanTemplateRecordSchema>
924
953
 
925
954
  export const PlanCycleRecordSchema = z.object({
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod'
2
2
 
3
- import { PlanArtifactKindSchema, PlanDraftSchema } from './execution-plan'
3
+ import { ArtifactKindSchema } from './artifact'
4
+ import { PlanDraftSchema } from './execution-plan'
4
5
 
5
6
  export const GraphDesignRequestSchema = z.object({
6
7
  objective: z.string().trim().min(1).max(4000),
@@ -8,7 +9,7 @@ export const GraphDesignRequestSchema = z.object({
8
9
  availableAgents: z.array(z.object({ agentId: z.string(), capabilities: z.array(z.string()) })),
9
10
  availablePlugins: z.array(z.object({ pluginRef: z.string(), operations: z.array(z.string()) })),
10
11
  contextArtifacts: z
11
- .array(z.object({ name: z.string(), kind: PlanArtifactKindSchema, summary: z.string().optional() }))
12
+ .array(z.object({ name: z.string(), kind: ArtifactKindSchema, summary: z.string().optional() }))
12
13
  .default([]),
13
14
  })
14
15
  export type GraphDesignRequest = z.infer<typeof GraphDesignRequestSchema>
@@ -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({