@opencode-ai/schema 0.0.0-next-15090 → 0.0.0-next-15092

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.
@@ -3,14 +3,18 @@ import { Schema } from "effect";
3
3
  import { optional } from "./schema.js";
4
4
  import { ToolContent } from "./llm.js";
5
5
  import { Model } from "./model.js";
6
- import { FileAttachment, Prompt } from "./prompt.js";
6
+ import { Prompt } from "./prompt.js";
7
7
  import { DateTimeUtcFromMillis, PositiveInt, RelativePath, statics } from "./schema.js";
8
- import { SessionID } from "./session-id.js";
9
8
  import { ascending } from "./identifier.js";
10
9
  import { Event } from "./event.js";
11
10
  import { Shell as ShellSchema } from "./shell.js";
12
11
  import { FinishReason } from "./llm.js";
13
12
  import { SessionError } from "./session-error.js";
13
+ import { Agent } from "./agent.js";
14
+ import { Skill as SkillSchema } from "./skill.js";
15
+ import { Money } from "./money.js";
16
+ import { Snapshot } from "./snapshot.js";
17
+ import { TokenUsage } from "./token-usage.js";
14
18
  export const ID = Schema.String.check(Schema.isStartsWith("msg_")).pipe(Schema.brand("Session.Message.ID"), statics((schema) => ({
15
19
  create: () => schema.make("msg_" + ascending()),
16
20
  fromEvent: (eventID) => schema.make(eventID.replace(/^evt_/, "msg_")),
@@ -25,12 +29,12 @@ export const ProviderState = Schema.Record(Schema.String, Schema.Unknown).annota
25
29
  });
26
30
  export const AgentSelected = Schema.Struct({
27
31
  ...Base,
28
- type: Schema.Literal("agent-switched"),
29
- agent: Schema.String,
32
+ type: Schema.tag("agent-switched"),
33
+ agent: Agent.ID,
30
34
  }).annotate({ identifier: "Session.Message.AgentSelected" });
31
35
  export const ModelSelected = Schema.Struct({
32
36
  ...Base,
33
- type: Schema.Literal("model-switched"),
37
+ type: Schema.tag("model-switched"),
34
38
  model: Model.Ref,
35
39
  previous: Model.Ref.pipe(optional),
36
40
  }).annotate({ identifier: "Session.Message.ModelSelected" });
@@ -39,66 +43,67 @@ export const User = Schema.Struct({
39
43
  text: Prompt.fields.text,
40
44
  files: Prompt.fields.files,
41
45
  agents: Prompt.fields.agents,
42
- type: Schema.Literal("user"),
46
+ type: Schema.tag("user"),
43
47
  }).annotate({ identifier: "Session.Message.User" });
44
48
  export const Synthetic = Schema.Struct({
45
49
  ...Base,
46
- sessionID: SessionID,
47
50
  text: Schema.String,
48
51
  description: Schema.String.pipe(optional),
49
- type: Schema.Literal("synthetic"),
52
+ type: Schema.tag("synthetic"),
50
53
  }).annotate({ identifier: "Session.Message.Synthetic" });
51
54
  export const System = Schema.Struct({
52
55
  ...Base,
53
- type: Schema.Literal("system"),
56
+ type: Schema.tag("system"),
54
57
  text: Schema.String,
55
58
  }).annotate({ identifier: "Session.Message.System" });
56
59
  export const Skill = Schema.Struct({
57
60
  ...Base,
58
- type: Schema.Literal("skill"),
59
- name: Schema.String,
61
+ type: Schema.tag("skill"),
62
+ skill: SkillSchema.ID,
63
+ name: SkillSchema.Name,
60
64
  text: Schema.String,
61
65
  }).annotate({ identifier: "Session.Message.Skill" });
62
66
  export const Shell = Schema.Struct({
63
67
  ...Base,
64
- type: Schema.Literal("shell"),
65
- shell: ShellSchema.Info,
68
+ type: Schema.tag("shell"),
69
+ shellID: ShellSchema.ID,
70
+ command: Schema.String,
71
+ status: ShellSchema.Status,
72
+ exit: Schema.Number.pipe(optional),
66
73
  output: ShellSchema.Output.pipe(optional),
67
74
  time: Schema.Struct({
68
75
  created: DateTimeUtcFromMillis,
69
76
  completed: DateTimeUtcFromMillis.pipe(optional),
70
77
  }),
71
78
  }).annotate({ identifier: "Session.Message.Shell" });
72
- export const ToolStatePending = Schema.Struct({
73
- status: Schema.Literal("pending"),
79
+ export const ToolStateStreaming = Schema.Struct({
80
+ status: Schema.tag("streaming"),
74
81
  input: Schema.String,
75
- }).annotate({ identifier: "Session.Message.ToolState.Pending" });
82
+ }).annotate({ identifier: "Session.Message.ToolState.Streaming" });
76
83
  export const ToolStateRunning = Schema.Struct({
77
- status: Schema.Literal("running"),
84
+ status: Schema.tag("running"),
78
85
  input: Schema.Record(Schema.String, Schema.Unknown),
79
86
  structured: Schema.Record(Schema.String, Schema.Unknown),
80
87
  content: ToolContent.pipe(Schema.Array),
81
88
  }).annotate({ identifier: "Session.Message.ToolState.Running" });
82
89
  export const ToolStateCompleted = Schema.Struct({
83
- status: Schema.Literal("completed"),
90
+ status: Schema.tag("completed"),
84
91
  input: Schema.Record(Schema.String, Schema.Unknown),
85
- attachments: FileAttachment.pipe(Schema.Array, optional),
86
92
  content: ToolContent.pipe(Schema.Array),
87
- outputPaths: Schema.Array(Schema.String).pipe(optional),
88
93
  structured: Schema.Record(Schema.String, Schema.Unknown),
89
94
  result: Schema.Unknown.pipe(optional),
90
95
  }).annotate({ identifier: "Session.Message.ToolState.Completed" });
91
96
  export const ToolStateError = Schema.Struct({
92
- status: Schema.Literal("error"),
97
+ status: Schema.tag("error"),
93
98
  input: Schema.Record(Schema.String, Schema.Unknown),
94
99
  content: ToolContent.pipe(Schema.Array),
95
100
  structured: Schema.Record(Schema.String, Schema.Unknown),
96
101
  error: SessionError.Error,
97
102
  result: Schema.Unknown.pipe(optional),
98
103
  }).annotate({ identifier: "Session.Message.ToolState.Error" });
99
- export const ToolState = Schema.Union([ToolStatePending, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(Schema.toTaggedUnion("status"));
104
+ export const ToolState = Schema.Union([ToolStateStreaming, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(Schema.toTaggedUnion("status"));
100
105
  export const AssistantTool = Schema.Struct({
101
- type: Schema.Literal("tool"),
106
+ type: Schema.tag("tool"),
102
107
  id: Schema.String,
103
108
  name: Schema.String,
104
109
  executed: Schema.Boolean.pipe(optional),
@@ -109,15 +114,14 @@ export const AssistantTool = Schema.Struct({
109
114
  created: DateTimeUtcFromMillis,
110
115
  ran: DateTimeUtcFromMillis.pipe(optional),
111
116
  completed: DateTimeUtcFromMillis.pipe(optional),
112
- pruned: DateTimeUtcFromMillis.pipe(optional),
113
117
  }),
114
118
  }).annotate({ identifier: "Session.Message.Assistant.Tool" });
115
119
  export const AssistantText = Schema.Struct({
116
- type: Schema.Literal("text"),
120
+ type: Schema.tag("text"),
117
121
  text: Schema.String,
118
122
  }).annotate({ identifier: "Session.Message.Assistant.Text" });
119
123
  export const AssistantReasoning = Schema.Struct({
120
- type: Schema.Literal("reasoning"),
124
+ type: Schema.tag("reasoning"),
121
125
  text: Schema.String,
122
126
  state: ProviderState.pipe(optional),
123
127
  time: Schema.Struct({
@@ -133,23 +137,18 @@ export const AssistantRetry = Schema.Struct({
133
137
  }).annotate({ identifier: "Session.Message.Assistant.Retry" });
134
138
  export const Assistant = Schema.Struct({
135
139
  ...Base,
136
- type: Schema.Literal("assistant"),
137
- agent: Schema.String,
140
+ type: Schema.tag("assistant"),
141
+ agent: Agent.ID,
138
142
  model: Model.Ref,
139
143
  content: AssistantContent.pipe(Schema.Array),
140
144
  snapshot: Schema.Struct({
141
- start: Schema.String.pipe(optional),
142
- end: Schema.String.pipe(optional),
145
+ start: Snapshot.ID.pipe(optional),
146
+ end: Snapshot.ID.pipe(optional),
143
147
  files: Schema.Array(RelativePath).pipe(optional),
144
148
  }).pipe(optional),
145
149
  finish: FinishReason.pipe(optional),
146
- cost: Schema.Finite.pipe(optional),
147
- tokens: Schema.Struct({
148
- input: Schema.Finite,
149
- output: Schema.Finite,
150
- reasoning: Schema.Finite,
151
- cache: Schema.Struct({ read: Schema.Finite, write: Schema.Finite }),
152
- }).pipe(optional),
150
+ cost: Money.USD.pipe(optional),
151
+ tokens: TokenUsage.Info.pipe(optional),
153
152
  error: SessionError.Error.pipe(optional),
154
153
  retry: AssistantRetry.pipe(optional),
155
154
  time: Schema.Struct({
@@ -157,15 +156,29 @@ export const Assistant = Schema.Struct({
157
156
  completed: DateTimeUtcFromMillis.pipe(optional),
158
157
  }),
159
158
  }).annotate({ identifier: "Session.Message.Assistant" });
160
- export const Compaction = Schema.Struct({
161
- type: Schema.Literal("compaction"),
162
- status: Schema.Literals(["queued", "running", "completed", "failed"]),
159
+ const CompactionBase = { type: Schema.tag("compaction"), ...Base };
160
+ export const CompactionRunning = Schema.Struct({
161
+ ...CompactionBase,
162
+ status: Schema.tag("running"),
163
163
  reason: Schema.Literals(["auto", "manual"]),
164
164
  summary: Schema.String,
165
165
  recent: Schema.String,
166
- ...Base,
167
- }).annotate({ identifier: "Session.Message.Compaction" });
168
- export const Message = Schema.Union([
166
+ }).annotate({ identifier: "Session.Message.Compaction.Running" });
167
+ export const CompactionCompleted = Schema.Struct({
168
+ ...CompactionBase,
169
+ status: Schema.tag("completed"),
170
+ reason: Schema.Literals(["auto", "manual"]),
171
+ summary: Schema.String,
172
+ recent: Schema.String,
173
+ }).annotate({ identifier: "Session.Message.Compaction.Completed" });
174
+ export const CompactionFailed = Schema.Struct({
175
+ ...CompactionBase,
176
+ status: Schema.tag("failed"),
177
+ reason: Schema.Literals(["auto", "manual"]),
178
+ error: SessionError.Error,
179
+ }).annotate({ identifier: "Session.Message.Compaction.Failed" });
180
+ export const Compaction = Schema.Union([CompactionRunning, CompactionCompleted, CompactionFailed]).pipe(Schema.toTaggedUnion("status"), Schema.annotate({ identifier: "Session.Message.Compaction" }));
181
+ export const Info = Schema.Union([
169
182
  AgentSelected,
170
183
  ModelSelected,
171
184
  User,
@@ -177,4 +190,4 @@ export const Message = Schema.Union([
177
190
  Compaction,
178
191
  ])
179
192
  .pipe(Schema.toTaggedUnion("type"))
180
- .annotate({ identifier: "Session.Message" });
193
+ .annotate({ identifier: "Session.Message.Info" });