Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typespec): Misc fixes in typespec definitions #638

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading