summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-03 14:24:45 -0400
committerDax Raad <[email protected]>2025-06-03 14:24:45 -0400
commitcaf9fdc893bfdda79450d62f9140a6a314ab1387 (patch)
treee02d22dc278e13c0cb7911063ceec00b27391fc3 /packages
parentbe4155a838bf8e34af239f3f68dc608b34725b4b (diff)
downloadopencode-caf9fdc893bfdda79450d62f9140a6a314ab1387.tar.gz
opencode-caf9fdc893bfdda79450d62f9140a6a314ab1387.zip
initialized
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/app/app.ts26
-rw-r--r--packages/opencode/src/server/server.ts20
-rw-r--r--packages/opencode/src/session/session.ts17
-rw-r--r--packages/tui/pkg/client/gen/openapi.json85
-rw-r--r--packages/tui/pkg/client/generated-client.go252
5 files changed, 382 insertions, 18 deletions
diff --git a/packages/opencode/src/app/app.ts b/packages/opencode/src/app/app.ts
index fc75cd26a..ed4408da0 100644
--- a/packages/opencode/src/app/app.ts
+++ b/packages/opencode/src/app/app.ts
@@ -10,15 +10,15 @@ export namespace App {
export const Info = z
.object({
- time: z.object({
- initialized: z.number().optional(),
- }),
git: z.boolean(),
path: z.object({
data: z.string(),
root: z.string(),
cwd: z.string(),
}),
+ time: z.object({
+ initialized: z.number().optional(),
+ }),
})
.openapi({
ref: "App.Info",
@@ -33,16 +33,12 @@ export namespace App {
)
const data = path.join(Global.data(), git ?? "global")
- await Bun.write(path.join(data, "version"), input.version)
const stateFile = Bun.file(path.join(data, "state"))
- const state = (
- (await stateFile.exists()) ? await stateFile.json() : {}
- ) as {
+ const state = (await stateFile.json().catch(() => ({}))) as {
initialized: number
version: string
}
state.version = input.version
- if (!git) state.initialized = Date.now()
await stateFile.write(JSON.stringify(state))
const services = new Map<
@@ -67,6 +63,7 @@ export namespace App {
},
}
const result = {
+ version: input.version,
services,
info,
}
@@ -102,7 +99,6 @@ export namespace App {
cb: T,
) {
const app = await create(input)
-
return ctx.provide(app, async () => {
const result = await cb(app.info)
for (const [key, entry] of app.services.entries()) {
@@ -112,4 +108,16 @@ export namespace App {
return result
})
}
+
+ export async function initialize() {
+ const { info, version } = ctx.use()
+ info.time.initialized = Date.now()
+ await Bun.write(
+ path.join(info.path.data, "state"),
+ JSON.stringify({
+ version,
+ initialized: Date.now(),
+ }),
+ )
+ }
}
diff --git a/packages/opencode/src/server/server.ts b/packages/opencode/src/server/server.ts
index 245ade4fe..9b370b04a 100644
--- a/packages/opencode/src/server/server.ts
+++ b/packages/opencode/src/server/server.ts
@@ -101,6 +101,26 @@ export namespace Server {
},
)
.post(
+ "/app_initialize",
+ describeRoute({
+ description: "Initialize the app",
+ responses: {
+ 200: {
+ description: "Initialize the app",
+ content: {
+ "application/json": {
+ schema: resolver(z.boolean()),
+ },
+ },
+ },
+ },
+ }),
+ async (c) => {
+ await App.initialize()
+ return c.json(true)
+ },
+ )
+ .post(
"/session_initialize",
describeRoute({
description: "Analyze the app and create an AGENTS.md file",
diff --git a/packages/opencode/src/session/session.ts b/packages/opencode/src/session/session.ts
index 52b954f93..190c93eea 100644
--- a/packages/opencode/src/session/session.ts
+++ b/packages/opencode/src/session/session.ts
@@ -350,6 +350,7 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
assistant.tokens = usage.tokens
await updateMessage(next)
},
+ toolCallStreaming: false,
abortSignal: abort.signal,
maxRetries: 6,
stopWhen: stepCountIs(1000),
@@ -403,6 +404,21 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
})
break
+ case "tool-call-streaming-start":
+ next.parts.push({
+ type: "tool-invocation",
+ toolInvocation: {
+ state: "call",
+ toolName: value.toolName,
+ toolCallId: value.toolCallId,
+ args: {},
+ },
+ })
+ break
+
+ case "tool-call-delta":
+ break
+
case "tool-result":
const match = next.parts.find(
(p) =>
@@ -566,5 +582,6 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
},
],
})
+ await App.initialize()
}
}
diff --git a/packages/tui/pkg/client/gen/openapi.json b/packages/tui/pkg/client/gen/openapi.json
index 7ca11e6b2..758d54620 100644
--- a/packages/tui/pkg/client/gen/openapi.json
+++ b/packages/tui/pkg/client/gen/openapi.json
@@ -44,6 +44,69 @@
"description": "Get app info"
}
},
+ "/app_initialize": {
+ "post": {
+ "responses": {
+ "200": {
+ "description": "Initialize the app",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "boolean"
+ }
+ }
+ }
+ }
+ },
+ "operationId": "postApp_initialize",
+ "parameters": [],
+ "description": "Initialize the app"
+ }
+ },
+ "/session_initialize": {
+ "post": {
+ "responses": {
+ "200": {
+ "description": "200",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "boolean"
+ }
+ }
+ }
+ }
+ },
+ "operationId": "postSession_initialize",
+ "parameters": [],
+ "description": "Analyze the app and create an AGENTS.md file",
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "sessionID": {
+ "type": "string"
+ },
+ "providerID": {
+ "type": "string"
+ },
+ "modelID": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "sessionID",
+ "providerID",
+ "modelID"
+ ]
+ }
+ }
+ }
+ }
+ }
+ },
"/path_get": {
"post": {
"responses": {
@@ -932,13 +995,8 @@
"App.Info": {
"type": "object",
"properties": {
- "time": {
- "type": "object",
- "properties": {
- "initialized": {
- "type": "number"
- }
- }
+ "git": {
+ "type": "boolean"
},
"path": {
"type": "object",
@@ -958,11 +1016,20 @@
"root",
"cwd"
]
+ },
+ "time": {
+ "type": "object",
+ "properties": {
+ "initialized": {
+ "type": "number"
+ }
+ }
}
},
"required": [
- "time",
- "path"
+ "git",
+ "path",
+ "time"
]
},
"Provider.Info": {
diff --git a/packages/tui/pkg/client/generated-client.go b/packages/tui/pkg/client/generated-client.go
index 4552a37b4..2d3369eac 100644
--- a/packages/tui/pkg/client/generated-client.go
+++ b/packages/tui/pkg/client/generated-client.go
@@ -26,6 +26,7 @@ const (
// AppInfo defines model for App.Info.
type AppInfo struct {
+ Git bool `json:"git"`
Path struct {
Cwd string `json:"cwd"`
Data string `json:"data"`
@@ -251,6 +252,13 @@ type PostSessionChatJSONBody struct {
SessionID string `json:"sessionID"`
}
+// PostSessionInitializeJSONBody defines parameters for PostSessionInitialize.
+type PostSessionInitializeJSONBody struct {
+ ModelID string `json:"modelID"`
+ ProviderID string `json:"providerID"`
+ SessionID string `json:"sessionID"`
+}
+
// PostSessionMessagesJSONBody defines parameters for PostSessionMessages.
type PostSessionMessagesJSONBody struct {
SessionID string `json:"sessionID"`
@@ -274,6 +282,9 @@ type PostSessionAbortJSONRequestBody PostSessionAbortJSONBody
// PostSessionChatJSONRequestBody defines body for PostSessionChat for application/json ContentType.
type PostSessionChatJSONRequestBody PostSessionChatJSONBody
+// PostSessionInitializeJSONRequestBody defines body for PostSessionInitialize for application/json ContentType.
+type PostSessionInitializeJSONRequestBody PostSessionInitializeJSONBody
+
// PostSessionMessagesJSONRequestBody defines body for PostSessionMessages for application/json ContentType.
type PostSessionMessagesJSONRequestBody PostSessionMessagesJSONBody
@@ -866,6 +877,9 @@ type ClientInterface interface {
// PostAppInfo request
PostAppInfo(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
+ // PostAppInitialize request
+ PostAppInitialize(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
+
// GetEvent request
GetEvent(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
@@ -888,6 +902,11 @@ type ClientInterface interface {
// PostSessionCreate request
PostSessionCreate(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
+ // PostSessionInitializeWithBody request with any body
+ PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
+
+ PostSessionInitialize(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
+
// PostSessionList request
PostSessionList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
@@ -919,6 +938,18 @@ func (c *Client) PostAppInfo(ctx context.Context, reqEditors ...RequestEditorFn)
return c.Client.Do(req)
}
+func (c *Client) PostAppInitialize(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
+ req, err := NewPostAppInitializeRequest(c.Server)
+ if err != nil {
+ return nil, err
+ }
+ req = req.WithContext(ctx)
+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {
+ return nil, err
+ }
+ return c.Client.Do(req)
+}
+
func (c *Client) GetEvent(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetEventRequest(c.Server)
if err != nil {
@@ -1015,6 +1046,30 @@ func (c *Client) PostSessionCreate(ctx context.Context, reqEditors ...RequestEdi
return c.Client.Do(req)
}
+func (c *Client) PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
+ req, err := NewPostSessionInitializeRequestWithBody(c.Server, contentType, body)
+ if err != nil {
+ return nil, err
+ }
+ req = req.WithContext(ctx)
+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {
+ return nil, err
+ }
+ return c.Client.Do(req)
+}
+
+func (c *Client) PostSessionInitialize(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
+ req, err := NewPostSessionInitializeRequest(c.Server, body)
+ if err != nil {
+ return nil, err
+ }
+ req = req.WithContext(ctx)
+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {
+ return nil, err
+ }
+ return c.Client.Do(req)
+}
+
func (c *Client) PostSessionList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewPostSessionListRequest(c.Server)
if err != nil {
@@ -1126,6 +1181,33 @@ func NewPostAppInfoRequest(server string) (*http.Request, error) {
return req, nil
}
+// NewPostAppInitializeRequest generates requests for PostAppInitialize
+func NewPostAppInitializeRequest(server string) (*http.Request, error) {
+ var err error
+
+ serverURL, err := url.Parse(server)
+ if err != nil {
+ return nil, err
+ }
+
+ operationPath := fmt.Sprintf("/app_initialize")
+ if operationPath[0] == '/' {
+ operationPath = "." + operationPath
+ }
+
+ queryURL, err := serverURL.Parse(operationPath)
+ if err != nil {
+ return nil, err
+ }
+
+ req, err := http.NewRequest("POST", queryURL.String(), nil)
+ if err != nil {
+ return nil, err
+ }
+
+ return req, nil
+}
+
// NewGetEventRequest generates requests for GetEvent
func NewGetEventRequest(server string) (*http.Request, error) {
var err error
@@ -1314,6 +1396,46 @@ func NewPostSessionCreateRequest(server string) (*http.Request, error) {
return req, nil
}
+// NewPostSessionInitializeRequest calls the generic PostSessionInitialize builder with application/json body
+func NewPostSessionInitializeRequest(server string, body PostSessionInitializeJSONRequestBody) (*http.Request, error) {
+ var bodyReader io.Reader
+ buf, err := json.Marshal(body)
+ if err != nil {
+ return nil, err
+ }
+ bodyReader = bytes.NewReader(buf)
+ return NewPostSessionInitializeRequestWithBody(server, "application/json", bodyReader)
+}
+
+// NewPostSessionInitializeRequestWithBody generates requests for PostSessionInitialize with any type of body
+func NewPostSessionInitializeRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
+ var err error
+
+ serverURL, err := url.Parse(server)
+ if err != nil {
+ return nil, err
+ }
+
+ operationPath := fmt.Sprintf("/session_initialize")
+ if operationPath[0] == '/' {
+ operationPath = "." + operationPath
+ }
+
+ queryURL, err := serverURL.Parse(operationPath)
+ if err != nil {
+ return nil, err
+ }
+
+ req, err := http.NewRequest("POST", queryURL.String(), body)
+ if err != nil {
+ return nil, err
+ }
+
+ req.Header.Add("Content-Type", contentType)
+
+ return req, nil
+}
+
// NewPostSessionListRequest generates requests for PostSessionList
func NewPostSessionListRequest(server string) (*http.Request, error) {
var err error
@@ -1507,6 +1629,9 @@ type ClientWithResponsesInterface interface {
// PostAppInfoWithResponse request
PostAppInfoWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInfoResponse, error)
+ // PostAppInitializeWithResponse request
+ PostAppInitializeWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInitializeResponse, error)
+
// GetEventWithResponse request
GetEventWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEventResponse, error)
@@ -1529,6 +1654,11 @@ type ClientWithResponsesInterface interface {
// PostSessionCreateWithResponse request
PostSessionCreateWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionCreateResponse, error)
+ // PostSessionInitializeWithBodyWithResponse request with any body
+ PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error)
+
+ PostSessionInitializeWithResponse(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error)
+
// PostSessionListWithResponse request
PostSessionListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionListResponse, error)
@@ -1570,6 +1700,28 @@ func (r PostAppInfoResponse) StatusCode() int {
return 0
}
+type PostAppInitializeResponse struct {
+ Body []byte
+ HTTPResponse *http.Response
+ JSON200 *bool
+}
+
+// Status returns HTTPResponse.Status
+func (r PostAppInitializeResponse) Status() string {
+ if r.HTTPResponse != nil {
+ return r.HTTPResponse.Status
+ }
+ return http.StatusText(0)
+}
+
+// StatusCode returns HTTPResponse.StatusCode
+func (r PostAppInitializeResponse) StatusCode() int {
+ if r.HTTPResponse != nil {
+ return r.HTTPResponse.StatusCode
+ }
+ return 0
+}
+
type GetEventResponse struct {
Body []byte
HTTPResponse *http.Response
@@ -1707,6 +1859,28 @@ func (r PostSessionCreateResponse) StatusCode() int {
return 0
}
+type PostSessionInitializeResponse struct {
+ Body []byte
+ HTTPResponse *http.Response
+ JSON200 *bool
+}
+
+// Status returns HTTPResponse.Status
+func (r PostSessionInitializeResponse) Status() string {
+ if r.HTTPResponse != nil {
+ return r.HTTPResponse.Status
+ }
+ return http.StatusText(0)
+}
+
+// StatusCode returns HTTPResponse.StatusCode
+func (r PostSessionInitializeResponse) StatusCode() int {
+ if r.HTTPResponse != nil {
+ return r.HTTPResponse.StatusCode
+ }
+ return 0
+}
+
type PostSessionListResponse struct {
Body []byte
HTTPResponse *http.Response
@@ -1804,6 +1978,15 @@ func (c *ClientWithResponses) PostAppInfoWithResponse(ctx context.Context, reqEd
return ParsePostAppInfoResponse(rsp)
}
+// PostAppInitializeWithResponse request returning *PostAppInitializeResponse
+func (c *ClientWithResponses) PostAppInitializeWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInitializeResponse, error) {
+ rsp, err := c.PostAppInitialize(ctx, reqEditors...)
+ if err != nil {
+ return nil, err
+ }
+ return ParsePostAppInitializeResponse(rsp)
+}
+
// GetEventWithResponse request returning *GetEventResponse
func (c *ClientWithResponses) GetEventWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEventResponse, error) {
rsp, err := c.GetEvent(ctx, reqEditors...)
@@ -1874,6 +2057,23 @@ func (c *ClientWithResponses) PostSessionCreateWithResponse(ctx context.Context,
return ParsePostSessionCreateResponse(rsp)
}
+// PostSessionInitializeWithBodyWithResponse request with arbitrary body returning *PostSessionInitializeResponse
+func (c *ClientWithResponses) PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) {
+ rsp, err := c.PostSessionInitializeWithBody(ctx, contentType, body, reqEditors...)
+ if err != nil {
+ return nil, err
+ }
+ return ParsePostSessionInitializeResponse(rsp)
+}
+
+func (c *ClientWithResponses) PostSessionInitializeWithResponse(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) {
+ rsp, err := c.PostSessionInitialize(ctx, body, reqEditors...)
+ if err != nil {
+ return nil, err
+ }
+ return ParsePostSessionInitializeResponse(rsp)
+}
+
// PostSessionListWithResponse request returning *PostSessionListResponse
func (c *ClientWithResponses) PostSessionListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionListResponse, error) {
rsp, err := c.PostSessionList(ctx, reqEditors...)
@@ -1960,6 +2160,32 @@ func ParsePostAppInfoResponse(rsp *http.Response) (*PostAppInfoResponse, error)
return response, nil
}
+// ParsePostAppInitializeResponse parses an HTTP response from a PostAppInitializeWithResponse call
+func ParsePostAppInitializeResponse(rsp *http.Response) (*PostAppInitializeResponse, error) {
+ bodyBytes, err := io.ReadAll(rsp.Body)
+ defer func() { _ = rsp.Body.Close() }()
+ if err != nil {
+ return nil, err
+ }
+
+ response := &PostAppInitializeResponse{
+ Body: bodyBytes,
+ HTTPResponse: rsp,
+ }
+
+ switch {
+ case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
+ var dest bool
+ if err := json.Unmarshal(bodyBytes, &dest); err != nil {
+ return nil, err
+ }
+ response.JSON200 = &dest
+
+ }
+
+ return response, nil
+}
+
// ParseGetEventResponse parses an HTTP response from a GetEventWithResponse call
func ParseGetEventResponse(rsp *http.Response) (*GetEventResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
@@ -2121,6 +2347,32 @@ func ParsePostSessionCreateResponse(rsp *http.Response) (*PostSessionCreateRespo
return response, nil
}
+// ParsePostSessionInitializeResponse parses an HTTP response from a PostSessionInitializeWithResponse call
+func ParsePostSessionInitializeResponse(rsp *http.Response) (*PostSessionInitializeResponse, error) {
+ bodyBytes, err := io.ReadAll(rsp.Body)
+ defer func() { _ = rsp.Body.Close() }()
+ if err != nil {
+ return nil, err
+ }
+
+ response := &PostSessionInitializeResponse{
+ Body: bodyBytes,
+ HTTPResponse: rsp,
+ }
+
+ switch {
+ case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
+ var dest bool
+ if err := json.Unmarshal(bodyBytes, &dest); err != nil {
+ return nil, err
+ }
+ response.JSON200 = &dest
+
+ }
+
+ return response, nil
+}
+
// ParsePostSessionListResponse parses an HTTP response from a PostSessionListWithResponse call
func ParsePostSessionListResponse(rsp *http.Response) (*PostSessionListResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)