Skip to content
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
2 changes: 2 additions & 0 deletions dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (d *dispatcher) handleRequest(payload []byte) []byte {
Query map[string]string `json:"query"`
ProjectID string `json:"project_id"`
CallerID string `json:"caller_id"`
UserID string `json:"user_id"`
CallerRole string `json:"caller_role"`
Headers map[string]string `json:"headers"`
Body []byte `json:"body"`
Expand All @@ -70,6 +71,7 @@ func (d *dispatcher) handleRequest(payload []byte) []byte {
Body: hr.Body,
Caller: CallerIdentity{
CallerID: hr.CallerID,
UserID: hr.UserID,
CallerRole: hr.CallerRole,
ProjectID: hr.ProjectID,
},
Expand Down
3 changes: 3 additions & 0 deletions native_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func (b *stubConfigBackend) Get(_ string) (string, bool) { return "", false }
// EmitEvent is a no-op outside WASM.
func EmitEvent(_ string, _ any) {}

// RecordActivity is a no-op outside WASM.
func RecordActivity(_, _, _, _ string, _ any) {}

// ptrOf and hostError are used by wasm_backends.go (wasip1 only); provide
// stubs here so the non-WASM build does not need them.
//nolint:unused // used in wasm_backends.go in WASM builds
Expand Down
3 changes: 3 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import "encoding/json"
type CallerIdentity struct {
// CallerID is the project_member UUID of the caller.
CallerID string `json:"caller_id"`
// UserID is the authenticated user's UUID (JWT sub claim).
// Use this as actor_id when recording task activities.
UserID string `json:"user_id"`
Comment thread
pikann marked this conversation as resolved.
// CallerRole is the role name of the caller within the project.
CallerRole string `json:"caller_role"`
// ProjectID is the project the request is scoped to.
Expand Down
32 changes: 32 additions & 0 deletions wasm_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,38 @@ func EmitEvent(topic string, payload any) {
)
}

// ── RecordActivity ────────────────────────────────────────────────────────────

// activityInput is the JSON shape sent to the paca.activity_record host function.
type activityInput struct {
TaskID string `json:"task_id"`
ProjectID string `json:"project_id"`
ActorID string `json:"actor_id"`
ActivityType string `json:"activity_type"`
Content any `json:"content"`
Comment thread
pikann marked this conversation as resolved.
}

// RecordActivity appends a task-activity event to the paca activity stream so
// that it is persisted to PostgreSQL by the ActivityConsumer worker.
// actorUserID should be req.Caller.UserID (the authenticated user's UUID).
// content must be JSON-encodable and match the expected shape for activityType.
func RecordActivity(taskID, projectID, actorUserID, activityType string, content any) {
inp := activityInput{
TaskID: taskID,
ProjectID: projectID,
ActorID: actorUserID,
ActivityType: activityType,
Content: content,
}
payloadBytes, err := json.Marshal(inp)
if err != nil {
return
}
if !hostActivityRecord(int64(ptrOf(payloadBytes)), int64(len(payloadBytes))) {
return
}
}

// ── Helpers ───────────────────────────────────────────────────────────────────

//go:nocheckptr
Expand Down
6 changes: 6 additions & 0 deletions wasm_imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func hostStorageDelete(keyPtr, keyLen int64) int32
//go:noescape
func hostEventEmit(topicPtr, topicLen, payloadPtr, payloadLen int64) int32

// paca.activity_record(payloadPtr i64, payloadLen i64) -> ok i32
//
//go:wasmimport paca activity_record
//go:noescape
func hostActivityRecord(payloadPtr, payloadLen int64) int32

// paca.config_get(keyPtr i64, keyLen i64, valuePtrPtr i64, valueLenPtr i64)
//
//go:wasmimport paca config_get
Expand Down
Loading