Skip to content

Commit b44a981

Browse files
authored
feat(core): global form support (anomalyco#35959)
1 parent 79415f6 commit b44a981

17 files changed

Lines changed: 493 additions & 93 deletions

File tree

‎packages/client/src/effect/api/api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ type Endpoint13_2Request = Parameters<RawClient["server.form"]["session.form.cre
526526
export type Endpoint13_2Input = {
527527
readonly sessionID: Endpoint13_2Request["params"]["sessionID"]
528528
readonly id?: Endpoint13_2Request["payload"]["id"]
529-
readonly title?: Endpoint13_2Request["payload"]["title"]
529+
readonly title: Endpoint13_2Request["payload"]["title"]
530530
readonly metadata?: Endpoint13_2Request["payload"]["metadata"]
531531
readonly mode: Endpoint13_2Request["payload"]["mode"]
532532
readonly fields?: Endpoint13_2Request["payload"]["fields"]

‎packages/client/src/effect/generated/client.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ type Endpoint13_2Request = Parameters<RawClient["server.form"]["session.form.cre
621621
type Endpoint13_2Input = {
622622
readonly sessionID: Endpoint13_2Request["params"]["sessionID"]
623623
readonly id?: Endpoint13_2Request["payload"]["id"]
624-
readonly title?: Endpoint13_2Request["payload"]["title"]
624+
readonly title: Endpoint13_2Request["payload"]["title"]
625625
readonly metadata?: Endpoint13_2Request["payload"]["metadata"]
626626
readonly mode: Endpoint13_2Request["payload"]["mode"]
627627
readonly fields?: Endpoint13_2Request["payload"]["fields"]

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,7 @@ export type FormRequestListOutput = {
25982598
| {
25992599
readonly id: string
26002600
readonly sessionID: string
2601-
readonly title?: string
2601+
readonly title: string
26022602
readonly metadata?: { readonly [x: string]: JsonValue }
26032603
readonly mode: "form"
26042604
readonly fields: ReadonlyArray<
@@ -2695,7 +2695,7 @@ export type FormRequestListOutput = {
26952695
| {
26962696
readonly id: string
26972697
readonly sessionID: string
2698-
readonly title?: string
2698+
readonly title: string
26992699
readonly metadata?: { readonly [x: string]: JsonValue }
27002700
readonly mode: "url"
27012701
readonly url: string
@@ -2710,7 +2710,7 @@ export type FormListOutput = {
27102710
| {
27112711
readonly id: string
27122712
readonly sessionID: string
2713-
readonly title?: string
2713+
readonly title: string
27142714
readonly metadata?: { readonly [x: string]: JsonValue }
27152715
readonly mode: "form"
27162716
readonly fields: ReadonlyArray<
@@ -2807,7 +2807,7 @@ export type FormListOutput = {
28072807
| {
28082808
readonly id: string
28092809
readonly sessionID: string
2810-
readonly title?: string
2810+
readonly title: string
28112811
readonly metadata?: { readonly [x: string]: JsonValue }
28122812
readonly mode: "url"
28132813
readonly url: string
@@ -2819,7 +2819,7 @@ export type FormCreateInput = {
28192819
readonly sessionID: { readonly sessionID: string }["sessionID"]
28202820
readonly id?: {
28212821
readonly id?: string | null
2822-
readonly title?: string
2822+
readonly title: string
28232823
readonly metadata?: { readonly [x: string]: JsonValue }
28242824
readonly mode: "form" | "url"
28252825
readonly fields?: ReadonlyArray<
@@ -2914,9 +2914,9 @@ export type FormCreateInput = {
29142914
> | null
29152915
readonly url?: string | null
29162916
}["id"]
2917-
readonly title?: {
2917+
readonly title: {
29182918
readonly id?: string | null
2919-
readonly title?: string
2919+
readonly title: string
29202920
readonly metadata?: { readonly [x: string]: JsonValue }
29212921
readonly mode: "form" | "url"
29222922
readonly fields?: ReadonlyArray<
@@ -3013,7 +3013,7 @@ export type FormCreateInput = {
30133013
}["title"]
30143014
readonly metadata?: {
30153015
readonly id?: string | null
3016-
readonly title?: string
3016+
readonly title: string
30173017
readonly metadata?: { readonly [x: string]: JsonValue }
30183018
readonly mode: "form" | "url"
30193019
readonly fields?: ReadonlyArray<
@@ -3110,7 +3110,7 @@ export type FormCreateInput = {
31103110
}["metadata"]
31113111
readonly mode: {
31123112
readonly id?: string | null
3113-
readonly title?: string
3113+
readonly title: string
31143114
readonly metadata?: { readonly [x: string]: JsonValue }
31153115
readonly mode: "form" | "url"
31163116
readonly fields?: ReadonlyArray<
@@ -3207,7 +3207,7 @@ export type FormCreateInput = {
32073207
}["mode"]
32083208
readonly fields?: {
32093209
readonly id?: string | null
3210-
readonly title?: string
3210+
readonly title: string
32113211
readonly metadata?: { readonly [x: string]: JsonValue }
32123212
readonly mode: "form" | "url"
32133213
readonly fields?: ReadonlyArray<
@@ -3304,7 +3304,7 @@ export type FormCreateInput = {
33043304
}["fields"]
33053305
readonly url?: {
33063306
readonly id?: string | null
3307-
readonly title?: string
3307+
readonly title: string
33083308
readonly metadata?: { readonly [x: string]: JsonValue }
33093309
readonly mode: "form" | "url"
33103310
readonly fields?: ReadonlyArray<
@@ -3406,7 +3406,7 @@ export type FormCreateOutput = {
34063406
| {
34073407
readonly id: string
34083408
readonly sessionID: string
3409-
readonly title?: string
3409+
readonly title: string
34103410
readonly metadata?: { readonly [x: string]: JsonValue }
34113411
readonly mode: "form"
34123412
readonly fields: ReadonlyArray<
@@ -3503,7 +3503,7 @@ export type FormCreateOutput = {
35033503
| {
35043504
readonly id: string
35053505
readonly sessionID: string
3506-
readonly title?: string
3506+
readonly title: string
35073507
readonly metadata?: { readonly [x: string]: JsonValue }
35083508
readonly mode: "url"
35093509
readonly url: string
@@ -3520,7 +3520,7 @@ export type FormGetOutput = {
35203520
| {
35213521
readonly id: string
35223522
readonly sessionID: string
3523-
readonly title?: string
3523+
readonly title: string
35243524
readonly metadata?: { readonly [x: string]: JsonValue }
35253525
readonly mode: "form"
35263526
readonly fields: ReadonlyArray<
@@ -3617,7 +3617,7 @@ export type FormGetOutput = {
36173617
| {
36183618
readonly id: string
36193619
readonly sessionID: string
3620-
readonly title?: string
3620+
readonly title: string
36213621
readonly metadata?: { readonly [x: string]: JsonValue }
36223622
readonly mode: "url"
36233623
readonly url: string
@@ -5339,7 +5339,7 @@ export type EventSubscribeOutput =
53395339
| {
53405340
readonly id: string
53415341
readonly sessionID: string
5342-
readonly title?: string
5342+
readonly title: string
53435343
readonly metadata?: { readonly [x: string]: unknown }
53445344
readonly mode: "form"
53455345
readonly fields: ReadonlyArray<
@@ -5436,7 +5436,7 @@ export type EventSubscribeOutput =
54365436
| {
54375437
readonly id: string
54385438
readonly sessionID: string
5439-
readonly title?: string
5439+
readonly title: string
54405440
readonly metadata?: { readonly [x: string]: unknown }
54415441
readonly mode: "url"
54425442
readonly url: string

‎packages/core/src/tool/question.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const Plugin = {
8181
forms
8282
.ask({
8383
sessionID: context.sessionID,
84+
title: "Questions",
8485
metadata: {
8586
kind: "question",
8687
tool: { messageID: context.assistantMessageID, callID: context.toolCallID },

‎packages/core/test/form.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const formID = Form.ID.create("frm_test")
1414
const input = {
1515
id: formID,
1616
sessionID: SessionSchema.ID.make("ses_test"),
17+
title: "Test form",
1718
mode: "form",
1819
fields: [{ key: "name", type: "string", required: true }],
1920
} satisfies Form.CreateInput
@@ -45,10 +46,12 @@ describe("Form", () => {
4546
const service = yield* Form.Service
4647
const created = yield* service.create({
4748
sessionID: "global",
49+
title: "MCP input",
4850
mode: "form",
4951
fields: [{ key: "name", type: "string", required: true }],
5052
})
5153
expect(created.sessionID).toBe("global")
54+
expect(created.title).toBe("MCP input")
5255

5356
const owned = yield* service.list({ sessionID: "global" })
5457
expect(owned.map((form) => form.id)).toEqual([created.id])
@@ -64,6 +67,7 @@ describe("Form", () => {
6467
const service = yield* Form.Service
6568
const created = yield* service.create({
6669
sessionID: "global",
70+
title: "Conditional form",
6771
mode: "form",
6872
fields: [
6973
{ key: "confirm", type: "boolean", required: true },
@@ -96,6 +100,7 @@ describe("Form", () => {
96100
]
97101
const created = yield* service.create({
98102
sessionID: "global",
103+
title: "Multiselect form",
99104
mode: "form",
100105
fields: [
101106
{ key: "langs", type: "multiselect", options },
@@ -118,6 +123,7 @@ describe("Form", () => {
118123
const service = yield* Form.Service
119124
const created = yield* service.create({
120125
sessionID: "global",
126+
title: "Dependent form",
121127
mode: "form",
122128
fields: [
123129
{ key: "a", type: "boolean" },
@@ -160,6 +166,7 @@ describe("Form", () => {
160166
]
161167
const created = yield* service.create({
162168
sessionID: "global",
169+
title: "Selection form",
163170
mode: "form",
164171
fields: [
165172
{ key: "langs", type: "multiselect", options },
@@ -191,6 +198,7 @@ describe("Form", () => {
191198
const service = yield* Form.Service
192199
const created = yield* service.create({
193200
sessionID: "global",
201+
title: "Cascading form",
194202
mode: "form",
195203
fields: [
196204
{ key: "a", type: "boolean" },
@@ -213,7 +221,7 @@ describe("Form", () => {
213221
Effect.gen(function* () {
214222
const service = yield* Form.Service
215223
const flipCreate = (fields: ReadonlyArray<Form.Field>) =>
216-
service.create({ sessionID: "global", mode: "form", fields }).pipe(Effect.flip)
224+
service.create({ sessionID: "global", title: "Invalid form", mode: "form", fields }).pipe(Effect.flip)
217225

218226
expect(
219227
yield* flipCreate([

‎packages/core/test/tool-question.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe("QuestionTool", () => {
156156
expect(assertions).toMatchObject([{ sessionID, action: "question", resources: ["*"] }])
157157
expect(capturedInput()).toEqual({
158158
sessionID,
159+
title: "Questions",
159160
metadata: { kind: "question", tool: { messageID: toolIdentity.assistantMessageID, callID: "call-question" } },
160161
mode: "form",
161162
fields: [
@@ -202,6 +203,7 @@ describe("QuestionTool", () => {
202203
})
203204
expect(capturedInput()).toEqual({
204205
sessionID,
206+
title: "Questions",
205207
metadata: { kind: "question", tool: { messageID: toolIdentity.assistantMessageID, callID: "call-question" } },
206208
mode: "form",
207209
fields: [],

‎packages/opencode/test/cli/run/noninteractive.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ok<T>(data: T) {
1010
}
1111

1212
function form(id: string, sessionID: string): FormInfo {
13-
return { id, sessionID, mode: "form", fields: [] }
13+
return { id, sessionID, title: "Input requested", mode: "form", fields: [] }
1414
}
1515

1616
function formCreated(info: FormInfo): V2Event {

‎packages/schema/src/form.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const InfoBase = {
106106
// elicitations can be attributed to real sessions, revert this to SessionID. Do not rely
107107
// on non-session owners anywhere else.
108108
sessionID: Schema.String,
109-
title: Schema.String.pipe(optional),
109+
title: Schema.String,
110110
metadata: Metadata.pipe(optional),
111111
}
112112

‎packages/sdk/js/src/v2/gen/types.gen.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,7 +3556,7 @@ export type FormMultiselectField = {
35563556
export type FormFormInfo = {
35573557
id: string
35583558
sessionID: string
3559-
title?: string
3559+
title: string
35603560
metadata?: FormMetadata
35613561
mode: "form"
35623562
fields: Array<FormStringField | FormNumberField | FormIntegerField | FormBooleanField | FormMultiselectField>
@@ -3565,7 +3565,7 @@ export type FormFormInfo = {
35653565
export type FormUrlInfo = {
35663566
id: string
35673567
sessionID: string
3568-
title?: string
3568+
title: string
35693569
metadata?: FormMetadata
35703570
mode: "url"
35713571
url: string
@@ -5832,7 +5832,7 @@ export type ProjectCurrent = {
58325832

58335833
export type FormCreatePayload = {
58345834
id?: string
5835-
title?: string
5835+
title: string
58365836
metadata?: FormMetadata
58375837
mode: "form" | "url"
58385838
fields?: Array<FormStringField | FormNumberField | FormIntegerField | FormBooleanField | FormMultiselectField>
@@ -9878,7 +9878,7 @@ export type FormMultiselectFieldV2 = {
98789878
export type FormFormInfoV2 = {
98799879
id: string
98809880
sessionID: string
9881-
title?: string
9881+
title: string
98829882
metadata?: FormMetadata
98839883
mode: "form"
98849884
fields: Array<FormStringFieldV2 | FormNumberField | FormIntegerField | FormBooleanField | FormMultiselectFieldV2>
@@ -9887,15 +9887,15 @@ export type FormFormInfoV2 = {
98879887
export type FormUrlInfoV2 = {
98889888
id: string
98899889
sessionID: string
9890-
title?: string
9890+
title: string
98919891
metadata?: FormMetadata
98929892
mode: "url"
98939893
url: string
98949894
}
98959895

98969896
export type FormCreatePayloadV2 = {
98979897
id?: string | null
9898-
title?: string
9898+
title: string
98999899
metadata?: FormMetadata
99009900
mode: "form" | "url"
99019901
fields?: Array<
@@ -10613,7 +10613,7 @@ export type FormMultiselectField1 = {
1061310613
export type FormFormInfo1 = {
1061410614
id: string
1061510615
sessionID: string
10616-
title?: string
10616+
title: string
1061710617
metadata?: FormMetadata1
1061810618
mode: "form"
1061910619
fields: Array<FormStringField1 | FormNumberField1 | FormIntegerField1 | FormBooleanField1 | FormMultiselectField1>
@@ -10622,7 +10622,7 @@ export type FormFormInfo1 = {
1062210622
export type FormUrlInfo1 = {
1062310623
id: string
1062410624
sessionID: string
10625-
title?: string
10625+
title: string
1062610626
metadata?: FormMetadata1
1062710627
mode: "url"
1062810628
url: string

‎packages/tui/src/component/prompt/index.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export function Prompt(props: PromptProps) {
629629

630630
createEffect(() => {
631631
if (!input || input.isDestroyed) return
632-
if (props.visible === false || dialog.stack.length > 0) {
632+
if (props.visible === false || props.disabled || dialog.stack.length > 0) {
633633
if (input.focused) input.blur()
634634
return
635635
}
@@ -1452,7 +1452,10 @@ export function Prompt(props: PromptProps) {
14521452
input.cursorColor = theme.text
14531453
}, 0)
14541454
}}
1455-
onMouseDown={(r: MouseEvent) => r.target?.focus()}
1455+
onMouseDown={(r: MouseEvent) => {
1456+
if (props.disabled) return
1457+
r.target?.focus()
1458+
}}
14561459
focusedBackgroundColor={theme.backgroundElement}
14571460
cursorColor={props.disabled ? theme.backgroundElement : theme.text}
14581461
syntaxStyle={syntax()}

0 commit comments

Comments
 (0)