Skip to content
Open
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
19 changes: 18 additions & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
version: v2
modules:
- path: proto/tim-api
name: buf.build/greylabs/tim-api
name: buf.build/settlerlabs/tim-api
- path: proto/tim-internal
name: buf.build/settlerlabs/tim-internal
lint:
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
- RPC_REQUEST_RESPONSE_UNIQUE
- RPC_RESPONSE_STANDARD_NAME
- AEP_0133_REQUEST_ID_FIELD
- AEP_0134_METHOD_SIGNATURE
- AEP_0134_REQUEST_MASK_REQUIRED
- AEP_0122_KEBAB_CASE_URIS
- AEP_0122_RESOURCE_COLLECTION_IDENTIFIERS
- AEP_0132_RESOURCE_REFERENCE_TYPE
- AEP_0133_RESOURCE_REFERENCE_TYPE
- AEP_0127_HTTP_ANNOTATION
- AEP_0121_RESOURCE_MUST_SUPPORT_LIST
deps:
- buf.build/googleapis/googleapis
- buf.build/bufbuild/protovalidate
Expand Down
19 changes: 17 additions & 2 deletions proto/tim-api/tim/api/thread/v1alpha1/thread_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";
import "tim/api/llm_response/v1alpha1/llm_response_types.proto";
import "tim/api/tool/v1alpha1/tool_types.proto";

// Threads are collections of context as events that represent an llm conversation
Expand Down Expand Up @@ -135,7 +134,7 @@ message LlmMessage {
google.protobuf.Timestamp create_time = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

// Token usage for this message (optional, set after LLM response)
tim.api.llm_response.v1alpha1.TokenUsage token_usage = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
TokenUsage token_usage = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

// Validation rules to ensure that the correct data is set based on the role type
option (buf.validate.message).cel = {
Expand Down Expand Up @@ -229,6 +228,22 @@ message ThreadStateChangeEvent {
ThreadLLMState llm_state = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// TokenUsage is the usage of tokens for an llm call.
// This is a user facing version of the internal TokenUsage message
message TokenUsage {
// The number of input tokens.
int64 input_tokens = 1;

// The number of output tokens.
int64 output_tokens = 2;

// The number of cache create tokens.
int64 cache_create_tokens = 3;

// The number of cache read tokens.
int64 cache_read_tokens = 4;
}
Comment on lines +231 to +245

@joroshiba joroshiba Oct 28, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one larger made here to avoid externalizing an internal type, I can't find any space we are actually populating this field at the moment though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue this is internal only data and doesn't need to be exposed externally. externally we could include credits a thread used but I think this is not exactly the same as llm token usage.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @mycodecrafting, I think it's probably best to move back to llm_response_types.proto


// An actor who may participate in creating LLM messages
enum LlmMessageRole {
// Default unspecified
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
syntax = "proto3";

package tim.api.llm_response.v1alpha1;
package tim.int.llm_response.v1alpha1;

import "aep/api/field_info.proto";
import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "tim/api/llm_response/v1alpha1/llm_response_types.proto";
import "tim/int/llm_response/v1alpha1/llm_response_types.proto";

// LlmResponseService is an internal service for providing llm responses
service LlmResponseService {
// Upload llm response events to the server
// Note: Client streaming RPCs cannot have HTTP annotations with path parameters
// This RPC is gRPC-only and excluded from HTTP/REST API generation
// buf:lint:ignore AEP_0127_HTTP_ANNOTATION_REQUIRED
rpc UploadLlmResponseEvents(stream UploadLlmResponseEventsRequest) returns (UploadLlmResponseEventsResponse) {}

// Provide the token usage for an LLM message
rpc PushLlmTokenUsage(PushLlmTokenUsageRequest) returns (PushLlmTokenUsageResponse) {
option (google.api.http) = {
post: "/v1alpha1/{path=orgs/*/users/*/threads/*/messages/*}:usage"
body: "*"
};
option (google.api.method_signature) = "path, token_usage";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package tim.api.llm_response.v1alpha1;
package tim.int.llm_response.v1alpha1;

import "buf/validate/validate.proto";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
syntax = "proto3";

package tim.api.thread_context.v1alpha1;
package tim.int.thread_context.v1alpha1;

import "aep/api/field_info.proto";
import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "tim/api/thread_context/v1alpha1/thread_context_types.proto";
import "tim/int/thread_context/v1alpha1/thread_context_types.proto";

// ThreadContextService is an internal service for accessing a thread's active context
service ThreadContextService {
// Get a thread's active context
rpc GetThreadContext(GetThreadContextRequest) returns (ThreadContext) {
option (google.api.http) = {get: "/v1alpha1/{path=orgs/*/users/*/threads/*}/context"};
option (google.api.method_signature) = "path";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package tim.api.thread_context.v1alpha1;
package tim.int.thread_context.v1alpha1;

import "buf/validate/validate.proto";
import "google/protobuf/any.proto";
Expand Down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit odd because both the internal and external servers run this service since it's needed for both internal tool calls (system & remote) and external tool exec runners (user-land and environment tools)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strongly opinionated here, but maybe best to default to this being in api then? Seems more correct IMHO that things in api could be both on the internal and external servers than an int service being available on the external server as well.

Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
syntax = "proto3";

package tim.api.tool_execution.v1alpha1;
package tim.int.tool_execution.v1alpha1;

import "aep/api/field_info.proto";
import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "tim/api/tool/v1alpha1/tool_types.proto";
import "tim/api/tool_execution/v1alpha1/tool_execution_types.proto";
import "tim/int/tool_execution/v1alpha1/tool_execution_types.proto";

// ToolExecutionService provides APIs for remote tool execution.
// This service is used by workers to fetch and execute tools.
// Workers receive tool call IDs via job queue, so List method is not needed.
// buf:lint:ignore AEP_0121_RESOURCE_MUST_SUPPORT_LIST
service ToolExecutionService {
// Get a specific tool call by its ID
rpc GetToolCall(GetToolCallRequest) returns (ToolCall) {
option (google.api.http) = {get: "/v1alpha1/{path=orgs/*/users/*/threads/*/toolCalls/*}"};
option (google.api.method_signature) = "path";
}

// Submit a tool execution result
rpc SubmitToolResult(SubmitToolResultRequest) returns (SubmitToolResultResponse) {
option (google.api.http) = {
post: "/v1alpha1/{path=orgs/*/users/*/threads/*/toolCalls/*}:submit"
body: "tool_result"
};
option (google.api.method_signature) = "path,tool_result";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package tim.api.tool_execution.v1alpha1;
package tim.int.tool_execution.v1alpha1;

import "buf/validate/validate.proto";
import "google/api/field_behavior.proto";
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/mapper/persona.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/resourcepath"
"github.com/Greybox-Labs/tim/tim-db/gen/db"
personav1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/persona/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread_context/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/thread_context/v1alpha1"
"github.com/jackc/pgx/v5/pgtype"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/mapper/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/resourcepath"
"github.com/Greybox-Labs/tim/tim-db/gen/db"
threadv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread_context/v1alpha1"
toolv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/tool/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/thread_context/v1alpha1"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/llm_response/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/pgnotifier"
"github.com/Greybox-Labs/tim/tim-api/internal/resourcepath"
"github.com/Greybox-Labs/tim/tim-db/gen/db"
llmresponsev1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/llm_response/v1alpha1"
llmresponsev1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/llm_response/v1alpha1"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/llm_response/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/database"
"github.com/Greybox-Labs/tim/tim-api/internal/job_queue"
apitools "github.com/Greybox-Labs/tim/tim-api/internal/tools"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/llm_response/v1alpha1/llm_responsev1alpha1connect"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/llm_response/v1alpha1/llm_responsev1alpha1connect"
)

const ResourceType = "llm_response"
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/thread_context/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/resourcepath"
"github.com/Greybox-Labs/tim/tim-db/gen/db"
threadv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread_context/v1alpha1"
threadcontextv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/thread_context/v1alpha1"
)

func (s *Service) GetThreadContext(
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/thread_context/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"connectrpc.com/connect"
"github.com/Greybox-Labs/tim/shared/logger"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/thread_context/v1alpha1/thread_contextv1alpha1connect"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/thread_context/v1alpha1/thread_contextv1alpha1connect"
)

const ResourceType = "thread_context"
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/tool_execution/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/Greybox-Labs/tim/tim-api/internal/resourcepath"
"github.com/Greybox-Labs/tim/tim-db/gen/db"
toolv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/tool/v1alpha1"
tool_executionv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/tool_execution/v1alpha1"
tool_executionv1 "github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/tool_execution/v1alpha1"
"github.com/jackc/pgx/v5/pgtype"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down
2 changes: 1 addition & 1 deletion tim-api/internal/services/tool_execution/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"connectrpc.com/connect"
"github.com/Greybox-Labs/tim/shared/logger"
"github.com/Greybox-Labs/tim/tim-api/internal/job_queue"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/api/tool_execution/v1alpha1/tool_executionv1alpha1connect"
"github.com/Greybox-Labs/tim/tim-proto/gen/tim/int/tool_execution/v1alpha1/tool_executionv1alpha1connect"
)

const ResourceType = "tool-call"
Expand Down
Loading
Loading