Skip to content

Commit

Permalink
Merge pull request #92 from widmogrod/feature/january-2024
Browse files Browse the repository at this point in the history
Improve finding package name and package paths
  • Loading branch information
widmogrod authored Jan 3, 2024
2 parents 1904710 + a7a8482 commit 5373aac
Show file tree
Hide file tree
Showing 34 changed files with 6,041 additions and 745 deletions.
3 changes: 0 additions & 3 deletions cmd/mkunion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,9 @@ func main() {

for _, x := range inferred.RetrieveShapes() {
tsr.AddShape(x)
tsr.FollowRef(x)
}
}

tsr.FollowImports()

err := tsr.WriteToDir(c.String("output-dir"))
if err != nil {
return fmt.Errorf("failed to write to dir %s: %w", c.String("output-dir"), err)
Expand Down
23 changes: 13 additions & 10 deletions example/my-app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,32 @@ import (
)

// this command make sure that all types that are imported will have generated typescript mapping
//go:generate mkunion shape-export --language=typescript -o ./workflow
//go:generate ../../cmd/mkunion/mkunion shape-export --language=typescript -o ./src/workflow

// this lines defines all types that should have typescript mapping
type (
Workflow = workflow.Worflow
Workflow = workflow.Workflow
State = workflow.State
Command = workflow.Command
Expr = workflow.Expr
Predicate = workflow.Predicate
Reshaper = workflow.Reshaper
Schema = schema.Schema
UpdateRecords = schemaless.UpdateRecords[schemaless.Record[any]]
FindingRecords = schemaless.FindingRecords[schemaless.Record[any]]
FindRecords = schemaless.FindingRecords[schemaless.Record[any]]
PageResult = schemaless.PageResult[schemaless.Record[any]]
FunctionOutput = workflow.FunctionOutput
FunctionInput = workflow.FunctionInput
)

//go:generate mkunion -name=ChatCMD
//go:generate ../../cmd/mkunion/mkunion -name=ChatCMD
type (
UserMessage struct {
Message string
}
)

//go:generate mkunion -name=ChatResult
//go:generate ../../cmd/mkunion/mkunion -name=ChatResult -v
type (
SystemResponse struct {
//ID string
Expand Down Expand Up @@ -348,9 +351,9 @@ func main() {
})

e.POST("/flow", TypedJSONRequest(
workflow.WorflowFromJSON,
workflow.WorflowToJSON,
func(x workflow.Worflow) (workflow.Worflow, error) {
workflow.WorkflowFromJSON,
workflow.WorkflowToJSON,
func(x workflow.Workflow) (workflow.Workflow, error) {
flow, ok := x.(*workflow.Flow)
if !ok {
return nil, errors.New("expected *workflow.Flow")
Expand Down Expand Up @@ -378,7 +381,7 @@ func main() {
return err
}

result, err := shared.JSONMarshal[workflow.Worflow](record.Data)
result, err := shared.JSONMarshal[workflow.Workflow](record.Data)
if err != nil {
if errors.Is(err, schemaless.ErrNotFound) {
return c.JSONBlob(http.StatusNotFound, []byte(`{"error": "not found"}`))
Expand Down Expand Up @@ -507,7 +510,7 @@ func main() {
return err
}

program, err := workflow.WorflowFromJSON(data)
program, err := workflow.WorkflowFromJSON(data)
if err != nil {
log.Errorf("failed to convert to workflow: %v", err)
return err
Expand Down
6 changes: 3 additions & 3 deletions example/my-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useEffect, useReducer, useState} from 'react';
import './App.css';
import * as openai from './workflow/'
import * as openai from './workflow/github_com_sashabaranov_go-openai'
import * as schemaless from './workflow/github_com_widmogrod_mkunion_x_storage_schemaless'
import * as workflow from './workflow/github_com_widmogrod_mkunion_x_workflow'
import * as schema from "./workflow/github_com_widmogrod_mkunion_x_schema";
Expand All @@ -15,7 +15,7 @@ function flowCreate(flow: workflow.Flow) {
.then(data => console.log("save-flow-result", data))
}

function flowToString(flow: workflow.Worflow) {
function flowToString(flow: workflow.Workflow) {
return fetch('http://localhost:8080/workflow-to-str', {
method: 'POST',
body: JSON.stringify(flow),
Expand Down Expand Up @@ -1264,7 +1264,7 @@ function PaginatedTable<T>(props: PaginatedTableProps<T>) {
}


function WorkflowToString(props: { flow?: workflow.Worflow }) {
function WorkflowToString(props: { flow?: workflow.Workflow }) {
const [str, setStr] = useState("")

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions example/my-app/src/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useEffect, useState} from "react";
import './Chat.css';
import * as openai from './workflow/index'
import * as openai from './workflow/github_com_sashabaranov_go-openai'
import {ChatCMD, ChatResult} from "./workflow/github_com_widmogrod_mkunion_exammple_my-app";

type Message = {
Expand Down Expand Up @@ -87,7 +87,7 @@ export function Chat({props}: ChatParams) {

let toolCalls = getToolCalls(data)
toolCalls.forEach((toolCall: openai.ToolCall) => {
props.onFunctionCall && props.onFunctionCall(toolCall.function);
props.onFunctionCall && toolCall.Function && props.onFunctionCall(toolCall.Function);
})
});

Expand Down
16 changes: 16 additions & 0 deletions example/my-app/src/workflow/github_com_sashabaranov_go-openai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//generated by mkunion
export type ToolCall = {
Index?: number,
ID?: string,
Type?: ToolType,
Function?: FunctionCall,
}

export type ToolType = string

export type FunctionCall = {
Name?: string,
Arguments?: string,
}


Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,53 @@ export type ChatResponses = {
Responses?: ChatResult[],
}

export type Schema = schema.Schema
export type ListWorkflowsFn = {
Count?: number,
Words?: string[],
EnumTest?: string,
}

export type PageResult = schemaless.PageResult<schemaless.Record<any>>

export type State = workflow.State

export type Command = workflow.Command

export type RefreshStates = {}

export type Service<CMD, State> = {}

export type UpdateRecords = schemaless.UpdateRecords<schemaless.Record<any>>

export type Expr = workflow.Expr
export type Workflow = workflow.Worflow

export type RefreshFlows = {}
export type RefreshStates = {}
export type FindingRecords = schemaless.FindingRecords<schemaless.Record<any>>

export type Workflow = workflow.Workflow

export type Predicate = workflow.Predicate

export type FunctionInput = workflow.FunctionInput

export type GenerateImage = {
Width?: number,
Height?: number,
}
export type State = workflow.State
export type Command = workflow.Command
export type Predicate = workflow.Predicate
export type ListWorkflowsFn = {
Count?: number,
Words?: string[],
EnumTest?: string,
}

export type Reshaper = workflow.Reshaper
export type UpdateRecords = schemaless.UpdateRecords<schemaless.Record<any>>

export type FindRecords = schemaless.FindingRecords<schemaless.Record<any>>

export type Schema = schema.Schema

export type FunctionOutput = workflow.FunctionOutput


//eslint-disable-next-line
import * as schema from './github_com_widmogrod_mkunion_x_schema'
//eslint-disable-next-line
import * as workflow from './github_com_widmogrod_mkunion_x_workflow'
import * as openai from './github_com_sashabaranov_go-openai'
//eslint-disable-next-line
import * as schemaless from './github_com_widmogrod_mkunion_x_storage_schemaless'
//eslint-disable-next-line
import * as openai from './'
import * as workflow from './github_com_widmogrod_mkunion_x_workflow'
//eslint-disable-next-line
import * as schema from './github_com_widmogrod_mkunion_x_schema'
Original file line number Diff line number Diff line change
Expand Up @@ -36,74 +36,4 @@ export type List = Schema[]

export type Map = {[key: string]: Schema}

export type Location = {
"$type"?: "schema.LocationField",
"schema.LocationField": LocationField
} | {
"$type"?: "schema.LocationIndex",
"schema.LocationIndex": LocationIndex
} | {
"$type"?: "schema.LocationAnything",
"schema.LocationAnything": LocationAnything
}

export type LocationField = {
Name?: string,
}

export type LocationIndex = {
Index?: number,
}

export type LocationAnything = {}

export type LocationUnionJSON = {
Type?: string,
LocationField?: json.RawMessage,
LocationIndex?: json.RawMessage,
LocationAnything?: json.RawMessage,
}
export type Part = {
Location?: string,
Acc?: Acc[],
}
export type Acc = {
Name?: string,
Index?: number,
Any?: boolean,
}
export type PathAst = {
Parts?: Part[],
}
export type Field = {
Name?: string,
Value?: Schema,
}
export type SchemaUnionJSON = {
Type?: string,
None?: json.RawMessage,
Bool?: json.RawMessage,
Number?: json.RawMessage,
String?: json.RawMessage,
Binary?: json.RawMessage,
List?: json.RawMessage,
Map?: json.RawMessage,
}
export type Max = {
Int?: number,
Int8?: number,
Int16?: number,
Int32?: number,
Int64?: number,
Float32?: number,
Float64?: number,
Uint?: number,
Uint8?: number,
Uint16?: number,
Uint32?: number,
Uint64?: number,
}
export type locres = {}

//eslint-disable-next-line
import * as json from './encoding_json'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,7 @@ export type WherePredicates = {
Predicate?: Predicate,
Params?: ParamBinds,
}
export type Expression = {
Or?: OrCondition[],
}
export type OrCondition = {
And?: Condition[],
}
export type Condition = {
Operand?: Comparable,
Not?: Condition,
}
export type Comparable = {
Location?: string,
Operator?: string,
BindName?: Value,
}
export type Value = {
BindName?: string,
Number?: number,
String?: string,
Bool?: string,
Location?: string,
}

export type Predicate = {
"$type"?: "predicate.And",
"predicate.And": And
Expand Down Expand Up @@ -72,6 +51,8 @@ export type BindValue = {
BindName?: BindName,
}

export type BindName = string

export type Literal = {
Value?: schema.Schema,
}
Expand All @@ -80,23 +61,8 @@ export type Locatable = {
Location?: string,
}

export type BindName = string
export type ParamBinds = {[key: BindName]: schema.Schema}
export type BindableUnionJSON = {
Type?: string,
BindValue?: json.RawMessage,
Literal?: json.RawMessage,
Locatable?: json.RawMessage,
}
export type PredicateUnionJSON = {
Type?: string,
And?: json.RawMessage,
Or?: json.RawMessage,
Not?: json.RawMessage,
Compare?: json.RawMessage,
}


//eslint-disable-next-line
import * as schema from './github_com_widmogrod_mkunion_x_schema'
//eslint-disable-next-line
import * as json from './encoding_json'
Loading

0 comments on commit 5373aac

Please sign in to comment.