Skip to content

Commit

Permalink
fix(typespec): Misc fixes in typespec definitions (#638)
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>

<!-- ELLIPSIS_HIDDEN -->

----

> [!IMPORTANT]
> Redefines `ChildStreamEndpoint`, updates dependencies, and removes
`YieldStep` from task definitions in typespec files.
> 
>   - **Behavior**:
> - Redefines `ChildStreamEndpoint` in `interfaces.tsp` to use
`SSEStream<StreamEvent<T>>`.
> - Removes `YieldStep` from task definitions in `endpoints.tsp` and
`openapi-0.4.0.yaml`.
>   - **Models**:
>     - Adds `StreamEvent<T>` union in `types.tsp`.
>   - **Dependencies**:
> - Updates `package.json` dependencies to `@typespec/[email protected]`,
`@typespec/[email protected]`, `@typespec/[email protected]`, and others.
>   - **Misc**:
>     - Adds `TasksGetRoute` interface in `endpoints.tsp`.
>     - Enables `omit-unreachable-types` in `tspconfig.yaml`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for 2f2eafe. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr authored Oct 13, 2024
1 parent e05c1a0 commit fecdc81
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 105 deletions.
41 changes: 19 additions & 22 deletions typespec/common/interfaces.tsp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import "@typespec/http";
import "@typespec/sse";

import "./scalars.tsp";
import "./types.tsp";

using TypeSpec.Http;
using TypeSpec.SSE;

namespace Common;

Expand Down Expand Up @@ -140,28 +142,6 @@ interface ChildLimitOffsetPagination<
};
}

interface ChildStreamEndpoint<
T,
DocString extends valueof string = "Stream events emitted by the parent"
> {
@get
@doc(DocString)
stream(
@path
@doc("ID of parent")
id: uuid,

@query
@doc("Next page token")
next_token: string | null = null,
): {
@header contentType: eventStream;

@body
@doc("Stream of events emitted by the parent")
body: T;
};
}

interface ChildCreateEndpoint<
CreateType,
Expand Down Expand Up @@ -274,3 +254,20 @@ interface ChildPatchEndpoint<
body: ResourceUpdatedResponse;
};
}

interface ChildStreamEndpoint<
T,
DocString extends valueof string = "Stream events emitted by the parent"
> {
@get
@doc(DocString)
stream(
@path
@doc("ID of parent")
id: uuid,

@query
@doc("Next page token")
next_token: string | null = null,
): SSEStream<StreamEvent<T>>;
}
9 changes: 8 additions & 1 deletion typespec/common/types.tsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import "@typespec/events";
import "@typespec/http";
import "@typespec/openapi";

using TypeSpec.Events;
using TypeSpec.Http;
using TypeSpec.OpenAPI;

Expand Down Expand Up @@ -51,4 +53,9 @@ model PaginationOptions {

/** Object to filter results by metadata */
@query metadata_filter: MetadataFilter,
}
}

@events
union StreamEvent<T> {
T;
}
3 changes: 3 additions & 0 deletions typespec/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace Api {
@route("/docs")
interface IndividualDocsRoute extends Docs.IndividualDocEndpoints {}

@route("/tasks")
interface TasksGetRoute extends Tasks.GetEndpoints {}

@route("/agents/{id}/tasks")
interface TasksRoute extends Tasks.Endpoints {}

Expand Down
136 changes: 92 additions & 44 deletions typespec/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions typespec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"version": "0.4.0",
"type": "module",
"dependencies": {
"@typespec/compiler": "^0.60.1",
"@typespec/http": "^0.60.0",
"@typespec/openapi": "^0.60.0",
"@typespec/openapi3": "^0.60.0",
"@typespec/rest": "^0.60.0",
"@typespec/versioning": "^0.60.1"
"@typespec/compiler": "^0.61.2",
"@typespec/events": "^0.61.0",
"@typespec/http": "^0.61.0",
"@typespec/openapi": "^0.61.0",
"@typespec/openapi3": "^0.61.0",
"@typespec/rest": "^0.61.0",
"@typespec/sse": "^0.61.0",
"@typespec/versioning": "^0.61.0"
},
"private": true
}
2 changes: 2 additions & 0 deletions typespec/tasks/endpoints.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Tasks;
// TASK ENDPOINTS
//

interface GetEndpoints extends GetEndpoint<Task, "Get a task by id"> {}

interface CreateOrUpdateEndpoints {
@post
@doc("Create or update a task")
Expand Down
1 change: 0 additions & 1 deletion typespec/tasks/steps.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ alias NonConditionalWorkflowStep =
| ReturnStep
| SleepStep
| ErrorWorkflowStep
| YieldStep
| WaitForInputStep;

alias ConditionalStep = IfElseWorkflowStep | SwitchStep;
Expand Down
Loading

0 comments on commit fecdc81

Please sign in to comment.