mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
feat: endpoint builder and API types
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/** Request/response fields of the three DashScope knowledge endpoints, mirrored from the verified kscli types. */
|
||||
|
||||
export interface ServiceListRequest {
|
||||
agent_scene: 'chat' | 'search'
|
||||
agent_name?: string
|
||||
page_number: number
|
||||
page_size: number
|
||||
}
|
||||
|
||||
export interface ServiceListRow {
|
||||
agent_id?: string
|
||||
agent_name?: string
|
||||
agent_scene?: string
|
||||
agent_status?: string
|
||||
pipeline_list?: { pipeline_id?: string; pipeline_name?: string }[]
|
||||
}
|
||||
|
||||
export interface ServiceListResponse {
|
||||
code?: string
|
||||
message?: string
|
||||
data?: { total_count?: number; rows?: ServiceListRow[] }
|
||||
}
|
||||
|
||||
export interface SearchRequest {
|
||||
query: string
|
||||
agent_id: string
|
||||
agent_version?: string
|
||||
images?: string[]
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
request_id?: string
|
||||
data?: {
|
||||
total?: number
|
||||
nodes?: { score: number; text: string; metadata?: Record<string, unknown> }[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface ChatRequest {
|
||||
input: { messages: { role: 'user' | 'assistant'; content: string }[] }
|
||||
parameters: { agent_options: { agent_id: string; agent_version?: string } }
|
||||
stream: true
|
||||
}
|
||||
|
||||
export interface ChatStreamChunk {
|
||||
output?: {
|
||||
choices?: {
|
||||
message?: { content?: string; extra?: { step_change?: string } }
|
||||
finish_reason?: string
|
||||
}[]
|
||||
}
|
||||
request_id?: string
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/** Protocol path constants and the workspace-subdomain URL builder (external API spec; not configurable). */
|
||||
|
||||
/** DashScope knowledge API paths, mirrored from the verified kscli endpoint table. */
|
||||
export const KB_PATHS = {
|
||||
serviceList: '/api/v1/indices/rag/app/list',
|
||||
search: '/api/v1/indices/knowledge/search',
|
||||
chat: '/api/v2/apps/knowledge/chat',
|
||||
} as const
|
||||
|
||||
/**
|
||||
* Build one knowledge API endpoint.
|
||||
* @param endpointHost - host suffix, e.g. `cn-beijing.maas.aliyuncs.com`.
|
||||
* @param workspaceId - Bailian workspace id used as the subdomain.
|
||||
* @param path - one {@link KB_PATHS} value.
|
||||
* @returns the absolute endpoint URL.
|
||||
*/
|
||||
export function kbEndpoint(endpointHost: string, workspaceId: string, path: string): string {
|
||||
return `https://${workspaceId}.${endpointHost}${path}`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { KB_PATHS, kbEndpoint } from '../src/endpoints.js'
|
||||
|
||||
describe('kbEndpoint', () => {
|
||||
it('builds the workspace-subdomain URL', () => {
|
||||
expect(kbEndpoint('cn-beijing.maas.aliyuncs.com', 'ws-1', KB_PATHS.search))
|
||||
.toBe('https://ws-1.cn-beijing.maas.aliyuncs.com/api/v1/indices/knowledge/search')
|
||||
})
|
||||
|
||||
it('keeps protocol paths as constants', () => {
|
||||
expect(KB_PATHS.chat).toBe('/api/v2/apps/knowledge/chat')
|
||||
expect(KB_PATHS.serviceList).toBe('/api/v1/indices/rag/app/list')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user